Forum Moderators: open
Here is the problem (simplified):
Want to change <input type='button' value='click me' onclick='myFunc(param)' id='btn_1'>
to <a href='#' onclick='myFunc(param)'>click me</a>
here is the javascript code to try and do this:
//GET THE INPUT
iObj = document.getElementById('btn_1');
var curEvent = iObj.getAttribute('onclick');
//or curEvent = iObj.onclick;
//CREATE A AND ADD INFO
var a1 = document.createElement("a");
a1.appendChild(document.createTextNode(iObj.value));
iObj = iObj.parentNode.replaceChild(a1, iObj);
iObj.setAttribute('onclick',function(){eval(curEvent);});
//or iObj.onclick = function(){eval(curEvent);};
works fine in FF, Google, etc...but not IE
Ive tried adding the onclick event to the <A> before replaceChild
If I just try and add an alert() or someother function it works fine. Seems to be an issue with replacing the onclick or something. Dont get any errors though.
Any help would be appreciated. I am attempting to implament CSS buttons on my site and dont want to go through each page and replace buttons and input tags.