On click event not getting cloned


Using jQuery 1.10 I’m cloning a div containing a button on which a click event is defined. The div gets cloned but not the click event.

I’ve seen this question asked many times (for example: Click action from cloned element does not work ) and all answers suggest to use clone(true) or clone(true, true).

This does not seem to work in this case.

I’ve made a small working example: (FIDDLE LINK: http://jsfiddle.net/wD3dq/1/ )


    <a href=# " id="clickMe">Click Me to add a new Div</a>
    <div id="elementHolder">
        <div id="webThumb5">
            <p>Test1 <a href="# " class="del_button " role="button ">Delete</a></p>
        <div id="webThumb6">
            <p>Test2 <a href="# " class="del_button " role="button ">Delete</a></p>
        <div id="webThumb7">
            <p>Test3 <a href="# " class="del_button " role="button ">Delete</a></p>
    <div id="divTemplate" style="display:none ">
        <p>Test <a href="# " class="del_button " role="button ">Delete</a></p>


#elementHolder div {
    border: 1px solid black;
    padding: 0.5em;
    margin: 0.2em;


var counter = 100;
$(document).ready(function () {
    $("#elementHolder a.del_button").click(function (event) {
        var parentDiv = $(event.target).parent().parent();
        alert("Id: " + parentDiv.attr('id'));
    $("#clickMe").click(function (event) {
        counter += 1;
        var newId = "webThumb" + counter;
        var newDiv = $("#divTemplate").clone(true, true);
        newDiv.attr("id", newId).prependTo("#elementHolder");

Any suggestions?


It does not clone the event since there is no event to clone.

You never assign a click event to divTemplate, you only do it to elementHolder which divTemplate is not a child of.

Get rid of worrying about cloning the event and just use bubbling

$("#elementHolder").on("click", "a.del_button", function (event) {
    var parentDiv = $(this).closest("div");
    alert("Id: " + parentDiv.attr('id'));

Answered By – epascarello

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published