jQuery filter function playing nice in Firefox but not Chrome
I have an <ul>
that if the child img is missing from the <li>
it needs t开发者_运维知识库o be removed. I am using jQuery 1.4.2.
$("#itemList ul li").filter(function() {
return $(this).children("img").length == 0;
}).remove();
This worked fine Firefox, did not throw any errors. All other major browsers threw an error. Using the following did not produce an error:
$("#slider ul li").each(function(index) {
if ($(this).children("img").length == 0)
{
$(this).remove();
}
});
Is this a bug in jQuery or is there something fundamental missing from my first line of code?
Is this what you try to achieve:
$("#itemList ul li:not(:has(img))").remove();
精彩评论