September 12, 2012

jquery nth selector in IE7

Question by Phil

I have a list of elements and need to make some amends to the first element in the list using jquery. I have tried a few methods to target the first item but none of them seem to work in IE7. These are the following methods I’ve tried…


All of these methods worked in all browsers except IE7, does anyone know of a fix to use for IE7 or a different method that will work in IE7?

Thanks in advance for any help?

Answer by Pradeeshnarayan

Try like this


Will get more info from here


Sorry for the confusion.
What I was trying to say is to use first-child instead of first()

You can use like this $('ul li:first-child').css('background-color', 'red');

Answer by Starx

.first() is a valid function and will work.

For example:

$("li").first(); // will match the first li in the tree

Please fill the form - I will response as fast as I can!