I have function which needs to be run on click event. However it is working fine with onclick attribute of anchor tag but not working with HREF attribute. It is giving id undefined. Here is demo code
HTML
<a href="javascript:test(this)" id="first">click</a>
JS
function test(obj){
alert(obj.id)
}
this in that context is the window, not the control. Placing javascript in the href is not the same as an event handler like onclick. Here's a fiddle.
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