当前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>
我需要使用jquery来替换,所以输出将是
<td rowspan="3" class="brandlogo">
<a href="newurl">
<img src="newimagesource" alt="" border="0" height="80" width="80">
</a>
</td>
答案 0 :(得分:1)
像这样:
var href = "newurl";
var imgPath = "newimagesource";//"newimagesource.jpg"
$('.brandlogo a').attr('href',href);
$('.brandlogo a img').attr('src',imgPath);
答案 1 :(得分:0)
您可以使用prop()
设置新值
$("td>a").prop("href", "newurl");
$("td>a>img").prop("src", "newimagesource");
$("td>a>img").prop("alt", "")