Current Record: How to dynamically change the onclick handler #83

News

Current Record: How to dynamically change the onclick handler #83

News

Click to minimize this section Details

News id 83
Headline How to dynamically change the onclick handler
Content More related to just web development in general, but sometimes you might need to change the onclick event handler of an element. This can be a little tricky, but I find the best way to do this is:br /br /blockquotebr /element.onclick = function() {this_is_my_function($param)}br //blockquotebr /br /The tricky part is that the value of the onclick is a span style="font-weight:bold;"reference/span to the function and not the function itself. So if you simply put:br /br /blockquoteelement.onclick = this_is_my_function($param)/blockquotebr /br /It would actually fail. You need to wrap this under another function, hence the original code where the function() calls the this_is_my_function().
Image (Empty)
Date posted Mon Feb 16 23:03:00 2009
Posted by noreply@blogger.com (Fong Chun Chan)
Status Approved
Categories Blog
Source id Fong's Blog
Source url http://fongxataface.blogspot.com/2009/02/how-to-dynamically-change-onclick.html
Powered by Xataface
(c) 2005-2024 All rights reserved