javascript - How to implement this remove function -


i'm trying make remove button removes between li tag button inside.

$(document).ready(function() {      $('#adicionar1').click(function() {         $('#list1').append("<li>"+ $("#texto1").val() +"<button>remover</button>" +"</li>"); $("#texto1").val("");             });      $('button').click(function() {       });   }); 

code: http://jsfiddle.net/bdmaf/917/

well can not add event element not exist. need either attach event when button added or use event delegation.

$('#list1').on("click", "li button", function() {  //listen click on button     $(this)  //the button clicked         .closest("li")  //find li element         .remove();      //remove li });