tags:

views:

81

answers:

6

i have a html mark up page who have a div ex:-

<div id="1" class="classic">i am text</div>
<div id="2"  class="classic">i am text</div>
<div id="3" class="classic">i am text</div>
<div id="4" class="classic">i am text</div>

how can i select a div who have this class and a specific id like 1. are you can show me how in jqury

+1  A: 

Since ids are unique, you could theoretically just use $('#1')

Ryan Kinal
Only within the page; the poster MIGHT be using the same jQuery across multiple pages, but only want to match the combination of class and id
Bobby Jack
... or, the OP may want the selector to fail if it doesn't find both: `#id.Selected`.
Kobi
@Kobi: yup, that's exactly what I meant :)
Bobby Jack
Good points! :-)
Ryan Kinal
A: 

since all elements should have unique IDs, $('#1') should work.

tenfour
+1  A: 

$('#1.classic') except you should have something like $('#one.classic') because ID attributes need to start with a letter.

Also you have an and in your HTML that really shouldn't be there.

Eton B.
+5  A: 
$('#ID.class')

e.g.

$('#one.classic')

is what you want; please create valid HTML first!

Bobby Jack
+4  A: 

I think the syntax you actually want is this:

$('#d1.classic')

That's grabbing by ID but only if it has the class. The presence or absence of the space is important. Also, ID's do need to start with a letter, they should not be purely numeric.

g.d.d.c
A: 

If you have an Id, then its supposed to be unique, so $('#1') will work, but the inner document.getElementById('1') will be a lot faster..

If you need to use jQuery, you can use $(document.getElementById('1')) and will be faster anyway...

If you need to select class and id anyway, you should use $('#1.classic')

NicolasT