NietzscheProgrammer NietzscheProgrammer - 3 months ago 9
Javascript Question

How to change specific href attribute with jQuery?

I have an element that I want to change in my page with 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>


I want to change that href which is automatically generated and put this instead:

https://www.bankofamerica.com/mortgage/


what can I do in this case?

Answer

Get element using name attribute with help of attribute equals selector and update href attribute using attr() method.

$('[name="affordableloansolutionmortgage_image_topicgrid"]').attr('href','https:‌​//www.bankofamerica.‌​com/mortgage/');
// or using class selector
$('.table-cell').attr('href','https:‌​//www.bankofamerica.‌​com/mortgage/');
Comments