I want after remove one of the rows (Ex: Row 2) in html code changed to in name element by jQuery.
For example we first have in html as:
Row 1: name=”check[0][]”
Row 2(removed): name=”check[1][]”
Row 3: name=”check[2][]”
Row 4: name=”check[3][]”
Now if we remove the second row, In fact, after removed the row 2, we have rows like this:
Row 1: name=”check[0][]”
Row 3: name=”check[2][]”
Row 4: name=”check[3][]”
But i want it in result (after remove one of rows ex: row 2) as:
Row 1: name=”check[0][]”
Row 3: name=”check[1][]”
Row 4: name=”check[2][]”
I tried as (see my full code) but Don’t work: http://jsfiddle.net/k3wne/
Js:
$('.remove_input').live('click', function (e) {
e.preventDefault();
var remove = $(this).closest($class);
remove.fadeOut('slow', function () {
$('.add_units').each(function (idx, val) {
var num = $('.add_units').length;
NumIdx = (num - (num - idx));
//for(var i = 0; i < num-1; i++){
$(this).closest($class_guide).next($class_guide).each(function (idx, val) {
$('.add_units input[type="checkbox"]').attr('name', function (idx, str) {
var int = parseInt(str.match(/\d+/)[0], 10);
return str.replace(int, NumIdx);
})
});
//}
})
});)
}
Here
DEMO
This code will work if you either