Changing onclick attribute using replace with jQuery
问题 Do someone know what is the best way to replace some string inside a onclick attribute ? I need to get the current value and replace some text inside parameters. Exemple, I have this link: <a href="#" onclick="myfunction('parameter1a','parameter1b')">My link</a> And I want this: <a href="#" onclick="myfunction('parameter2a','parameter2b')">My link</a> In other words, I want something like this: $('a').attr('onclick', $(this).attr('onclick').replace('1', '2')); And I know I can do this, but I