MShack
MShack

Reputation: 652

jquery solution to replace an img link with new image and link

Current HTML

<td rowspan="3" class="brandlogo">
<a href="http://www.myfantasyleague.com/">
<img src="http://www5.myfantasyleague.com/images/new_mfl_logo.png" alt="http://www.myfantasyleague.com/" border="0" height="80" width="80">
</a>
</td>

I need to use jquery to replace so the output would be

<td rowspan="3" class="brandlogo">
<a href="newurl">
<img src="newimagesource" alt="" border="0" height="80" width="80">
</a>
</td>

Upvotes: 0

Views: 53

Answers (2)

asdf_enel_hak
asdf_enel_hak

Reputation: 7640

You can use prop() to set new values

$("td>a").prop("href", "newurl");
$("td>a>img").prop("src", "newimagesource");
$("td>a>img").prop("alt", "")

Upvotes: 0

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

Like this:

var href = "newurl";
var imgPath = "newimagesource";//"newimagesource.jpg"
$('.brandlogo a').attr('href',href);
$('.brandlogo a img').attr('src',imgPath);

Upvotes: 1

Related Questions