Here is a sample of what I’m trying to achieve.
<script>
function test()
{
onclick_old = document.getElementById('testbutton').onclick;
onclick_new = onclick_old.replace('this','that');
document.getElementById('testbutton').setAttribute('onclick',onclick_new);
}
</script>
<input type="button" onclick="test();" value="change onclick" />
<input id="testbutton" type="button" onclick="alert('this');" />
But when running this, it says
TypeError: onclick_old.replace is not a function
Which makes sense, onclick_old in this case isn’t a string, but I want to treat it as such. How can I get around this?
Thanks in advanced