Reputation: 75
Every time I click on a button I want its z-index to increase one by one. How can I do it?
$('#Box').css('z-index', 'newindex');
Upvotes: 0
Views: 175
Reputation: 7489
You can use jQuery's .css
method both to get and set a particular value.
Since you want to take the current value and increment it, you would first use $('#Box').css('z-index')
to get the value, then you would increment it and pass it to $('#Box').css('z-index', newvalue)
.
Upvotes: 0
Reputation: 207521
Read the index. Add one to the index. Reset the index with the new value.
var myElem = $('#Box');
var currentIndex = myElem.css('z-index') || 0;
myElem.css('z-index', currentIndex+1);
Upvotes: 0