How can I use jQuery to replace part of the onclick property / attribute? In the example below I would like to replace delete_image with do_delete_image:
Sample HTML
<a href="#" onclick="delete_image(1234)" >Delete Image</a>
My Attempt
jQuery('a').each(function(){
var action = $(this).prop('onclick').replace('delete_image','do_delete_image');
$(this).prop('onclick',action);
});
Error
Google chrome is throwing this error:
TypeError: Object function onclick(event) { delete_image(1234);return false; } has no method 'replace'
How can I make this work? ps: This is a bookmarklet set to work with someone else's code.