user505210
user505210

Reputation: 1402

finding elements with z-index

I was working on an issue in which I was looping through same controls placed on a single page and assigning a z-index to them.

I want to get a collection of all the elements which currently have the z index defined either directly in html or using css, and then iterate over them top to bottom and assign their z-index using JQuery.

What would the selector for this look like, and how performant would it be?

Upvotes: 0

Views: 95

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337627

There is no specific selector to achieve this, so you would need to use filter() like this:

var zIndex = 5;
var $zElements = $('.selector').filter(function() {
    return $(this).css('z-index') == zIndex;
});

$zElements.each(function() {
    // loop through the elements with a matching z-index
});

Upvotes: 3

Related Questions