jQuery selector not working properly. Possible Sizzle bug?
I work in web development. jQuery is what I live and breathe. Just
recently (as of going to >= 1.10.1) jQuery is having "hickups" with
selectors. For example, selecting $("#catalog") will only return one
element, whereas selecting $("div#catalog") returns two. Also, I have had
issues in the recent past where a selector such as $("#page_id >
div.my_class .all_children") returned nothing, but
$("#page_id").find("div.my_class").find(".all_children") returned what I
wanted it to (no working example currently).
I DO have a reproducible example on jsFiddle that has the same "problem"
on Firefox and Chrome (I haven't tested any other browser). I thought I
would post this here first to get input before I post it as a bug on
jQuery.com.
Am I doing something wrong? Do I misunderstand Sizzle and selectors? I
know the "div#id" is generally faster than just "#id" (correct?), but
shouldn't they both work anyway?
$(document).ready(function () {
alert("Selector (#catalog): " + $("#catalog").length + " / " +
$("#catalog").find(".field_grid").length);
console.debug("Without div: ", $("#catalog"),
$("#catalog").find(".field_grid"));
alert("Selector (div#catalog): " + $("div#catalog").length + " / " +
$("div#catalog").find(".field_grid").length);
console.debug("With div: ", $("div#catalog"),
$("div#catalog").find(".field_grid"));
});
The above code will return different results, even though the selectors
are nearly identical.
Take a look at the fiddle: http://jsfiddle.net/AVWgW/2/ Also, take a look
at the console, I am dumping the return objects from jQuery.
Ideas?
No comments:
Post a Comment