unable to trigger event in IE during clonning

Posted by Abhimanyu on Stack Overflow See other posts from Stack Overflow or by Abhimanyu
Published on 2010-05-01T19:52:39Z Indexed on 2010/05/01 19:57 UTC
Read the original article Hit count: 242

Filed under:
|

Following is the code which will clone a set of div with their events(onclick) which is working fine for FF but in case of IE it is not firing events associated with each div.

 <html>
    <head>
    <style type='text/css'>
    .firstdiv{
       border:1px solid red;
    }
    </style>

    <script language="JavaScript">
    function show_tooltip(idx,condition,ev) {
        alert(idx +"=="+condition+"=="+ev);
    }

    function createCloneNode () {
        var cloneObj = document.getElementById("firstdiv").cloneNode(true);
        document.getElementById("maindiv").appendChild(cloneObj);
    }
    function init(){
     var mainDiv = document.createElement("div");
     mainDiv.id = 'maindiv';
     var firstDiv = document.createElement("div");
     firstDiv.id ='firstdiv';
     firstDiv.className ='firstdiv';
     for(var j=0;j<4;j++) {
       var summaryDiv = document.createElement("div");
            summaryDiv.id = "sDiv"+j
            summaryDiv.className ='summaryDiv';
            summaryDiv.onmouseover = function() {this.setAttribute("style","text-decoration:underline;cursor:pointer;");}
            summaryDiv.onmouseout = function() {this.setAttribute("style","text-decoration:none;");}
            summaryDiv.setAttribute("onclick", "show_tooltip("+j+",'view_month',event)");
            summaryDiv.innerHTML = 'Div'+j;
           firstDiv.appendChild(summaryDiv);
     } 

     mainDiv.appendChild(firstDiv);
     var secondDiv = document.createElement("div");
     var linkDiv = document.createElement("div");
     linkDiv.innerHTML ='create clone of above element';
     linkDiv.onclick = function() {
        createCloneNode();
     }
     secondDiv.appendChild(linkDiv);
     mainDiv.appendChild(secondDiv);
     document.body.appendChild(mainDiv);
    }
    </script>
    </head>
    <body>
    <script language="JavaScript">
    init()
    </script>
    </body>
    </html>

can anybody tell me whats the problem in above code please correct me..

© Stack Overflow or respective owner

Related posts about javascript-events

Related posts about dom