Reputation: 96810
I'm using $('div').css('color', 'red');
but I want the 5th div in my code to have red text. How would I do this?
Upvotes: 0
Views: 68
Reputation: 147373
POJS:
document.getElementsByTagName('div')[5].style.color = 'red';
It might be boring, but it's 20 to 30 times faster than the jQuery equivalent in IE 8.
Upvotes: 0
Reputation: 28598
You can use the :eq jQuery selector. See jsFiddle here:
Also see this SOq:
Upvotes: 0
Reputation: 5650
To answer the title question, if the particular element is named foo, you would use $('#foo')
.
Upvotes: 0
Reputation: 8198
$('div:eq(4)').css('color', 'red')
the :eq selector takes a 0-based integer
Upvotes: 4