开发者

jQuery filter function playing nice in Firefox but not Chrome

开发者 https://www.devze.com 2023-01-06 11:24 出处:网络
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.

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.

I used:

$("#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();
0

精彩评论

暂无评论...
验证码 换一张
取 消