Language: Javascript (View Plain Text)
January 28, 2010 3:35 am
//Find each link or input with a hard coded onclick method jQuery.each(jQuery("a[onclick], input[onclick]"), function(){ //create an "onclickmethod" attribute and assign it the FUNCTION DEFINITION of the onclick method (in order to cache it for later use) jQuery(this).attr("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).attr("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 function named clickMethod holding the anonymous function created above eval("clickMethod = " + methodString); //execute the clickMethod function (call the original click event) clickMethod(e); } });