Hi. I have a list of text input fields, which can be added and moved freely by clicking buttons.
They are like
write1 [text: ] [up] [down] [delete]
write2 [text: ] [up] [down] [delete]
...
[button: add text input field]
[up] [down] buttons move the corresponding text fields accordingly. [delete] button is obviously to remove the text input area together with up, down, and delete buttons.
Certainly, if I delete a line in the middle like below, the order of "id" attributes is now messed up.
write1 [text: ] [up] [down] [delete] (id="num1")
write2 [text: ] [up] [down] [delete] (id="num2")
write3 [text: ] [up] [down] [delete] (id="num3")
But I wish to reorganize the "id" attributes accordingly. Of course, similarly for up and down buttons.
=>
write1 [text: ] [up] [down] [delete] (id="num1")
write2 [text: ] [up] [down] [delete] (id="num2")
So, I need to implement jQuery code so that every button click updates all id values.
I tried...
- <tr>
- <td><input type="text" name="c_change" class="choice_input" id="num1"/></td>
- <td><button class="up">up</button> <button class="down">down</button></td>
- <td><button class="deleteButton">delete</button></td>
- </tr>
$('.deleteButton').live('click',function(event){
$(this).parent().parent().remove();
$('.choice_input').removeAttr('id');
$(".choice_input").attr("id", function (arr) {
return "num" + arr;
})
});
// up
$('.up').live('click',function(event){
var own = $(this).parent().parent();
var pre = own.prev();
own.insertBefore(pre);
});
for the delete and up buttons, hoping that removeAttr() removes all id attributes. But it does not.
Could anyone give me tips?