Friday 15 January 2010

Change specific attribute of href link with jQuery -



Change specific attribute of href link with jQuery -

i need alter 1 specific attribute of href link.

i have code this:

<div id="123">change id</div> <a id="link-to-change" href="/something/?id=0&value=15"></a>

when click on <div> need alter id in href link div's id. href link dynamic variable.

i tried this:

$( "#123" ).click(function() { var newid = $(this).attr('id'); $("#link-to-change").attr('href', function(){ homecoming $(this).attr('href').replace(/(id=)[1-9]+/ig, newid ); }); });

i dont know what's wrong , if regex correct.

could help me? thanks.

jquery

No comments:

Post a Comment