After append() how to bind a click event to just added element

Posted by Pentium10 on Stack Overflow See other posts from Stack Overflow or by Pentium10
Published on 2010-03-16T20:59:18Z Indexed on 2010/03/16 21:01 UTC
Read the original article Hit count: 207

Filed under:
|
|

I have this code

$(".delete2").click(function() {
  $('#load2').fadeIn();
}

I have dynamically added item via this return

addSubcategory = function(){
        sucategorynameval = $("#sucategoryname").val(); 
        categoryId        = $("#addcategoryid").val(); 
        $.get("process-add-subcat.php", { "action": "add_subcategory", "sucategoryname": sucategorynameval, "categoryId":categoryId },
               function(data){
                 //$("#main-cat-"+categoryId).load(location.href+"&pageExclusive=1 #main-cat-"+categoryId+">*","");
                 $("#main-cat-"+categoryId).append(data);
                 $("#addcategoryid").val(''); 
                 $("#sucategoryname").val(''); 
               }); 

The returned data contains delete2 classed item.

How do I apply the click event to the newly added item?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about append