Is there any alternative to doing the following line:
document.getElementById("btn").setAttribute("onclick", "save(" + id + ");");
This line basically changes the onclick() event of a button to something like: save(34); , save(35); etc. However it fails in IE 7 and 6 but works in IE 8 and Firefox.
I can use jquery for this as well.
Plain old javascript:
var myButton = document.getElementById("btn");
myButton.onclick = function()
{
save(id); //where does id come from?
}
jQuery:
$(function(){
$("#btn").click(function(){
save(id); //where does id come from?
});
});
If you can use jQuery, then:
$("#btn").click(function() { save(id); })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With