Loading...

Viewing Fixee

Language: Javascript (View Plain Text)

January 28, 2010 3:35 am

  1. //Find each link or input with a hard coded onclick method
  2. jQuery.each(jQuery("a[onclick], input[onclick]"), function(){
  3. //create an "onclickmethod" attribute and assign it the FUNCTION DEFINITION of the onclick method (in order to cache it for later use)
  4. jQuery(this).attr("onclickmethod", jQuery(this).attr("onclick").toString());
  5. //remove the onclick function bind
  6. jQuery(this).removeAttr("onclick");
  7. });
  8. jQuery("a, input").live("click", function(e){
  9. //Do your thing here...
  10.  
  11. //grab the "cached" function definition for the originally bound onclick method
  12. var methodString = jQuery(this).attr("onclickmethod");
  13. //if the element had an onclickmethod attr, continue on in order to execute it
  14. if(!!methodString){
  15. //remove the " onclick" leaving just an annonymous function definition
  16. var reg = / onclick/;
  17. methodString = methodString.replace(reg, '');
  18. //create a function named clickMethod holding the anonymous function created above
  19. eval("clickMethod = " + methodString);
  20. //execute the clickMethod function (call the original click event)
  21. clickMethod(e);
  22. }
  23. });