JQuery way to push an item at the top of a z-index?

What are the ways to find the highest CSS z-index value for a given set of elements and click on one element that is pressed at the top of the z-index order.

+4
source share
2 answers

You can try something simple:

var elements = $('selector').click(function(){ $(this).css('z-index', max++); }), max = Math.max.apply(Math, elements.map(function() { return parseInt($(this).css('z-index'), 10) || 0; }).get()); 

This will cause each clicked item in the set to receive a z-index one higher than the current one.

Edit: A new method for calculating the maximum z-index using Math.max kindly provided by AndyE in the chat: http://chat.stackoverflow.com/transcript/message/96656#96656 p>

+4
source

You can use this plugin.

+2
source

All Articles