Reputation: 409
Im trying to write a jquery code which hides all elements which have a z-index of less than 1. I haven't the slightest idea where to start.
Upvotes: 0
Views: 157
Reputation: 992
The simplest method is to write a filter function. Then call hide on each.
$("div").filter(function(){
return $(this).css('z-index') <= 1;
}).each(function(){ $(this).hide() });
Upvotes: 0
Reputation: 318302
I'd do it this way:
$('body *').css('display', function() { // don't hide the head / body / html tag
return this.style.zIndex > 0 ? this.style.display : 'none';
});
Upvotes: 2
Reputation: 781721
("*").filter(function() {
var zindex = $(this).css("z-index");
return (zindex !== undefined) && zindex < 1;
}).hide();
Upvotes: 3