Jake Schievink
Jake Schievink

Reputation: 409

Hide all elements with a z-index less than 1

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

Answers (3)

Nikhil Ranjan
Nikhil Ranjan

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

adeneo
adeneo

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

Barmar
Barmar

Reputation: 781721

("*").filter(function() {
    var zindex = $(this).css("z-index");
    return (zindex !== undefined) && zindex < 1;
}).hide();

Upvotes: 3

Related Questions