How to change onclick
using Javascript ?
https://jsfiddle.net/749rt0m7/1/
I tried to use this code, but it does not work. How can I do it?
<span onclick="test_fn('aaa,bbb')" id="xx">edit</span>
<script>
document.getElementById('xx').onclick = "test_fn(111,222)";
</script>
Basic onclick syntax Note that the onclick attribute is purely JavaScript. The value it takes, which is the function you want to execute, says it all, as it is invoked right within the opening tag.
document.getElementById('xx').onclick = function() {
test_fn(111, 222);
};
When setting onclick
in HTML, use a string. When setting it through JS, use a function.
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