Change the value of an existing onclick function
        Posted  
        
            by Mark Peach
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mark Peach
        
        
        
        Published on 2009-01-22T18:36:50Z
        Indexed on 
            2010/05/20
            4:50 UTC
        
        
        Read the original article
        Hit count: 269
        
jQuery
|JavaScript
I have a page that is pulling in via an iframe a page of html content from a pre-existing content management system, whose content I can not directly change. I want to use jquery to alter some of the links and button locations dynamically.
For links within the page I was able to change the href attr values of
<a href="/content.asp">more</a>
from content.asp to content2.asp using
$("a[href^='/content.asp']")
.each(function()   {       this.href = this.href.replace("content.asp",          "content2.asp");   });
But the page pulled in also has form buttons that contains javascript onclick functions e.g.
<INPUT type="button" value="Add to basket" onClick="document.location='/shopping-basket.asp?mode=add&id_Product=1076';">
I basically want to use jquery to select any such buttons and change the shopping-basket.asp to shopping-basket2.asp
How can I select these buttons/onclick functions and change the location string?
© Stack Overflow or respective owner