klewis
klewis

Reputation: 8350

jquery - add element text value to end of URL

I have a value that loooks like this on top of my page...

<div id="mid">
    <span>992839283</span>
</div>

...and I always want to copy it to the end of my URL further down page...

<div class="murl">
<a href="http://othersite.com/page/go.aspx?id=">my link</a>
</div>

...so what is the best way to get my URL to look like this when the window is ready...

<div class="murl">
<a href="http://othersite.com/page/go.aspx?id=992839283">my link</a>
</div>

I have no idea how to add this value to the end of my URL with minimal code.

thanks for any advice

Upvotes: 0

Views: 600

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

You may use attr with function:

$('.murl a').attr('href',function(i,v){
   return v + $('#mid').text();
});

Upvotes: 3

Related Questions