How to hide an dom element after creating it on the fly with Jquery ?
- by ismaelsow
I am trying to build a form where users can add a text field by clicking on a "add option" button. They can also remove added fields by a "remove option" link created on the fly by Jquery, along with the text field. My code looks like this :
$(document).ready(function(){
$("#add_option").click(function(){
var form = $("form");
var input_field = '<input type="text" />';
var delete_link = '<a href="#">remove</a>';
form.append(input_field + delete_link);
return false;
});
$("a").click(function(){
alert('clicked');
return false;
});
});
This code is not working : when I click on the "add_option" button, a new text field and the "delete_link" appear. But when clicking on the "delete_link" created by JQuery, the browser follows the link instead of launching a pop-up displaying "clicked". Any idea ?
Thanks !