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…
$(this).eq(1)
$(this).first()
$(this:nth-child(1))
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
$(this:first-child)
Will get more info from here
EDIT
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');