Jquery replace input button onclick event
I have HTML loaded with the Jquery .load method and need to dynamically change anchor HREF and input but开发者_开发问答ton ONCLICK targets in this HTML on the client as the page loads, (I don't have the option to change the server generated HTML).
The .load works fine and I can change the HREF target OK but I can't find a way of changing the ONCLICK target?
HTML
Anchor HREF
<div style="width:143px;" id="LM_OBJV"> <span title="View Objectives Detail" class="PSHYPERLINK"> <a class="PSHYPERLINK" href="javascript:Action_win0 (document.win0,'LM_OBJV','Relationship Building',false,true);" tabindex="54" id="LM_OBJV" name="LM_OBJV">Relationship Building</a> </span> </div>
Button ONCLICK
<div id="win0divLM"> <a id="Left" style="background-Color: transparent;border:0;" class="PBUTTON"> <span style="background-Color: transparent;"> <input type="button" onclick="Action_win0(document.win0,'LM_PB', 0, 0, 'Add New', false, true);" style="width:120px; " class="PBUTTON" value="Add New" tabindex="77" id="LM_PB" name="LM_PB"> </span> </a> </div>
Javascript
$('#result').load('some.php', function() {
$("a.PSHYPERLINK")
.each(function()
{
this.href = this.href.replace("Action_win0", "Action_winx");
});
});
So this JS works fine, loads the HTML into the #results DIV and changes the HREF's from "Action_win0" to "Action_winx".
But how can I also change the input type="button ONCLICK events from "Action_win0" to "Action_winx"? I've tried several Jquery selectors but just can't get it to work :(
$('a.PSHYPERLINK').attr('onclick', 'alert("bar")')
Demo: http://jsfiddle.net/kzVSt/
精彩评论