Wednesday, December 17, 2008

Javascript : Dynamically setting onclick event

hey friends,
some time ago I was working on a project which required a little functionality. I was trying to implement that using dynamically adding an onclick event to the anchor tag using DOM. As it seems too easy to deal, it was not too straight. so after some googling i found following code which is now working in IE and FireFox both.


if(navigator.userAgent.indexOf("Gecko")>-1)
signIn.setAttribute("onclick","functionName(args)");
else
signIn.onclick = function() { functionName(args) }

1 comment:

  1. Hi Prashant,
    At last i found a solution for my problem. Thanks for your code.

    ReplyDelete

Please add your valuable comments about this post if it helped you. Thanks

Popular Posts