Skip to content Skip to sidebar Skip to footer

Remove And Replace Another Onclick Function In A Div Through Pure Javascript?

I have this below span div and I copy this to another place in the DOM. But the onclick function I need to remove and place another onclick function. id="abc"></span> </div> <div id ="d2"> </div> </body> </html>

Now to move the element with id abc from DOM element with id d1 to another with id d2

//get the element
var element = document.getElementById("abc");

//detach from source
document.getElementById("d1").removeChild(element);

//remove onclick attribute
element.removeAttribute("onclick");

//add the modified attribute
element.setAttribute("onclick", "sampleFunc()");

//attach the element to another source
document.getElementById("d2").appenChild(element);

Solution 2:

document.getElementById("abc").onclick = function (){checkNodes('childNode1');}

Post a Comment for "Remove And Replace Another Onclick Function In A Div Through Pure Javascript?"