Reputation: 85565
I'm trying to remove the images which don't have the class.
html
<div id="slider">
<img class="" />
<img class="" />
<img class="img1" />
<img class="img2" />
<img class=" " />
</div>
jQuery
if(!$('#slider img').class()){
$('#slider img').remove(); // but I'm stucked at this line
}
Upvotes: 0
Views: 37
Reputation: 388316
I think what you can do is remove images whose class attribute value does not begin with img
$('#slider img:not([class^=img])').remove();
but a more correct solution will be
$('#slider img').filter(function () {
return $.trim(this.className).length === 0
}).remove();
Upvotes: 3
Reputation: 6275
Select everything, then filter out the things you don't want...
$("#slider img")
.filter(function(i) { return $(this).attr("class") == ""; })
.remove();
Upvotes: 0
Reputation: 526
$("#slider img").each(function(i){
if($(this).class=""){
//do whatever
}
});
Upvotes: 0