How to hide an dom element after creating it on the fly with Jquery ?

Posted by ismaelsow on Stack Overflow See other posts from Stack Overflow or by ismaelsow
Published on 2010-04-02T14:26:54Z Indexed on 2010/04/02 14:33 UTC
Read the original article Hit count: 187

Filed under:
|

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 !

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript