javascript – How to change the value of a "data" attribute in JQuery?

Question:

I have a data-order attribute on a button and I want it to increment as I add new days to my list via the click of the button, so I have:

day-1
day-2
day-3
day-4

… and so on. Does anyone know how I can increment this value in jQuery?

PS: The button has a unique ID. I just don't know how to increment.

EDIT: The question is not about concatenation, but about changing the data-order . I only have one of these attributes and I want to change its value from day-1 to day-2 .

Answer:

var valor = 0;
$('#botao').on('click', function () {
    valor++;
    $(this).data('order', 'day-' + valor);
});

I made a change to the example just to make the illustration easier. http://jsfiddle.net/Agr7p/10/ Hugs!

Scroll to Top