views:

1289

answers:

2

i have a div with many many html elements like other divs, trs, tds, tables etc

is it possible to get all the elements which have an id? i know asking $("#test") will give me the specific element with this id

but is it possible to get find("#") or something like this?!

greetz

+20  A: 

$('[id]') returns all elements that have id set

RaYell
Warning - this will be quite slow on a large dom
redsquare
+1, elegant solution
Clement Herreman
+1  A: 

You should look into documentation on their selectors. This will show you exactly what to do in any situation when you are selecting something.

Also note that you can use more than one selector at a time, like their example:

$("div,span,p.myClass").css("border","3px solid red");
Sneakyness
Stackoverflow isn't made to "read the manual" answer, it is made to give help, that's why you get my -1.
Clement Herreman
This is NOT a read the manual answer. It gives you a list of selectors and everything that you can do with them. It is impossible for me to give him an exact answer without seeing the entire page, knowing exactly what he wants selected.It is extremely straightforward, and is something he will end up looking at quite often until he gets used to selecting things. Would you rather come here and ask a question for each type of new selection you make, or have a list of everything you can do with them as well as correct syntax?
Sneakyness
Not ONLY that, but it also goes on to list many other useful time-savers, like filters, and ancestry. This is honestly one of the most useful page for people just starting to write in jQuery, and I wish I would have had it when I started learning jQuery.
Sneakyness