Is it possible to obtain the id of an element (div, input etc) using jQuery and how?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See Attributes/attr
Simple example:
If there is more than one div with the class
someclass(that is to say, the selector returns more than one element), you can get them all by looping through the elements using each, and pushing the ids into an array for example:Just to go a little further, you can use attribute filters (in this case
attributeHas) to pick out only those elements that have ids, e.g.:and finally, instead of using each, you can use
map( callback )which provides a neater way of doing the above: