Ganesh Yadav
Ganesh Yadav

Reputation: 2685

Re-order array on click

I have array[1,2,3,4,5,6]. Onclick select button I'm able to increment array. But on click remove button, I want to reset array e.g. [1,2,3,4] if I remove number 2 array then order should become [1,2,3]. Basically, re-order in increment order.

Fiddle Working Demo

var spl = $('.cc').text();
var tc = spl.split("").sort();
var l = 0; 
var p = [];
l = l % tc.length;
$('.cc').text(tc[l]);

enter image description here

Upvotes: 2

Views: 477

Answers (1)

R.Costa
R.Costa

Reputation: 1393

You can use the function filter to update the numbers of each element:

$('.counter').filter(function() {
    return parseInt(this.innerHTML) > cnt;
}).each(function() {
    var c = $(this).text();
    $(this).text(--c);
});

A working example based on your code:

JSFIDDLE

Upvotes: 2

Related Questions