views:

25

answers:

1

I have an <ul> that if the child img is missing from the <li> it needs to 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?

+3  A: 

Is this what you try to achieve:

$("#itemList ul li:not(:has(img))").remove();
Gert G
Yes, that is what I am trying to achieve and it can be done in a few forms, but I was just enquiring whether this was a bugin jQuery or a bug in the code, browser, etc. I wasn't really after another way to do it. But thanks anyway.
jpcmorton
I checked your code in IE 8, Iron 5.0.380, Firefox 3.6.6 and Opera 10.60... no problem. I hope that answers your question.
Gert G