Language: Javascript (View Plain Text) (Show diff)
February 1, 2010 12:21 am
//Find each link or input with a hard coded onclick method jQuery.each(jQuery("a[onclick], input[onclick]"), function(){ //store the FUNCTION DEFINITION of the onclick method (in order to cache it for later use) jQuery(this).data("onclickmethod", jQuery(this).attr("onclick").toString()); //remove the onclick function bind jQuery(this).removeAttr("onclick"); }); jQuery("a, input").live("click", function(e){ //Do your thing here... //grab the "cached" function definition for the originally bound onclick method var methodString = jQuery(this).data("onclickmethod"); //if the element had an onclickmethod attr, continue on in order to execute it if(!!methodString){ //remove the " onclick" leaving just an annonymous function definition var reg = / onclick/; methodString = methodString.replace(reg, ''), //create a local function named clickMethod holding the anonymous function created above clickMethod = eval("(" + methodString + ")"); //execute the clickMethod function (call the original click event) clickMethod(e); } });