How can I replace the onclick action (with regex) using javascript / jQuery?
<p>How can I use jQuery to replace part of the <code>onclick</code> property / attribute? In the example below I would like to replace <code>delete_image</code> with <code>do_delete_image</code>:</p>

<h3>Sample HTML</h3>

<pre><code>&lt;a href="#" onclick="delete_image(1234)" &gt;Delete Image&lt;/a&gt;
</code></pre>

<h3>My Attempt</h3>

<pre><code>jQuery('a').each(function(){
    var action = $(this).prop('onclick').replace('delete_image','do_delete_image');
    $(this).prop('onclick',action);
});
</code></pre>

<h3>Error</h3>

<p>Google chrome is throwing this error:</p>

<blockquote>
  <p>TypeError: Object function onclick(event) { delete_image(1234);return false; } has no method 'replace'</p>
</blockquote>

<p>How can I make this work? ps: This is a bookmarklet set to work with someone else's code.</p>
