TSkora
TSkora

Reputation: 75

Increase a value on a click

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

Answers (4)

Kami
Kami

Reputation: 19407

Try:

$('#Box').css('z-index',$('#Box').css('z-index') + 1);

Upvotes: 0

user1726343
user1726343

Reputation:

For jQuery 1.6 and later, use:

$('#Box').css('z-index','+=1');

Upvotes: 2

yoozer8
yoozer8

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

epascarello
epascarello

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

Related Questions