Trying to select a sibling element using jQuery and it doesn\'t work in IE7.
Here is my sample code: http://jsfiddle.net/y7AHz/6/ (click Run to see result)
This will also work in IE7:
var foo= $("#txtInput + ul.ulContainer");
var numberOfListItems = $('li', foo).length;
$("#output").text(numberOfListItems);
Not sure which of the proposed fixes performs best, if it matters...
This is a known bug with sizzle (the selector engine underneath jQuery) in IE6 and 7. Instead, use .next()
, which is equivalent to the +
or next adjacent
selector, and .find()
. It's more verbose, but it works in IE6+:
var numberOfListItems = $("#txtInput").next(".ulContainer").find("li").length;
Updated jsFiddle
try only this it works in ie7 also
var numberOfListItems = $("ul.ulContainer li").length;