Right now, I have elements with different z-index
, and I want to group them using jQuery.
If you add this function, then you will have them
$.fn.filterByZIndex = function(zIndex) {
var $zElm = $("*").filter(function() {
return $(this).css('z-index') == zIndex;
});
return $zElm;
};
Create your own custom selector:
$.extend($.expr[':'], {
zindex: function(el, i, m) {
return $(el).css("z-index") === m[3];
}
});
Which you could then use like this:
$("div:zindex(2)").each(function(){
alert( this.innerHTML );
});
This will return all div
elements with a z-index
of 2
.
<div style="position:relative; z-index:2">Foo</div>
<div style="position:relative; z-index:6">Bar</div>
With the above markup, the earlier jQuery script will alert Foo
.
Demo: http://jsbin.com/icevih/2/edit