change the value of the button of the button clicked

Posted by user269431 on Stack Overflow See other posts from Stack Overflow or by user269431
Published on 2010-02-15T12:37:20Z Indexed on 2010/03/26 2:33 UTC
Read the original article Hit count: 654

Filed under:

On inserting the new <li>, I have to set the value of the button clicked to Delete. How can I do that?

With the actual code, it`s working only once, and on adding other list, the button no more has the the value 'Delete'.

$("#mylist :button").click( function() { 
    var text = $(this).val(); 

    if (text == "Delete") { 
        $(this).parent().remove(); 
    } else { 
        $(this).val("Delete"); 
    }
});

$("#mylist li:last-child").live('click', function() { 
    $(this).parent().append('<li>' + '<input type = "textbox">' + 
        '<input type = "button" value= "Save">' + '</li>');
});

<div>
    <ul id="mylist">
        <li id="1">1<button id="Button3">Delete</button> </li> 
        <li id="2">2<button id="Button2">Delete</button></li> 
        <li id="3">3<button id="another_entry">Save</button></li>
    </ul>

© Stack Overflow or respective owner

Related posts about jQuery