tags:

views:

28

answers:

2

I have this HTML:

<div id="main"><div id="mainly">11</div><div id="mainly">22</div></div>

I want to select the div with value 11.How to do this? I tried:

$("<div id="mainly">11</div>")

,but it didn't work... I don't have only two divs with id="mainly".

+2  A: 

I don't have only two divs with id="mainly"

But you should have only one div with the id "mainly" !

DOM identifiers have to be unique in order to create a "well formed" and valid markup.

So, we just assume you'are using classes instead of ids.

$('.mainly:contains(11)').fadeOut('fast');
jAndy
+1 for actually getting to the heart of the question (`:contains`) despite the fact that ID's are being misused. mind you, contains will not look for exact matches, though, so `2112` will still match.
David Hedlund
@David: pretty true, but OP asked for exact matches, otherwise I would have suggested a `custom selector` using regular expressions :)
jAndy
+2  A: 

You can't have two or more div elements with the same id. This is invalid html and jQuery selectors won't work. Instead of ids use a common class for all the elements.

kgiannakakis