我想用jQuery在我的页面中更改一个元素:
<a class="table-cell" title="Affordable Loan Solution™ Mortgage" href="/en/articles/affordable-loan-solution-mortgage.html" name="affordableloansolutionmortgage_image_topicgrid">
<span class="linkwidth"> Affordable Loan Solution™ Mortgage </span>
<img alt="Affordable Loan Solution™ Mortgage" src="/res/img/topic/article.gif">
</a>
我想更改自动生成的href并将其改为:
https://www.bankofamerica.com/mortgage/
在这种情况下我该怎么办?
答案 0 :(得分:3)
在attribute equals selector的帮助下使用name属性获取元素,并使用attr()
方法更新href
属性。
$('[name="affordableloansolutionmortgage_image_topicgrid"]').attr('href','https://www.bankofamerica.com/mortgage/');
// or using class selector
$('.table-cell').attr('href','https://www.bankofamerica.com/mortgage/');