Mr A
Mr A

Reputation: 6768

using replace with to replace link with other link at runtime using jquery

I have got two links :

<li><a href="/newproducts" id="quiklinks_02">New products</a>

<a href="/c/13/latest-products"/>

I want to replace the href="/c/13/latest-products" with href="/newproducts" , how can i acheive this using replace with.

Regards

Upvotes: 0

Views: 62

Answers (2)

Royi Namir
Royi Namir

Reputation: 148524

$('li a:eq(1)').attr('href',$('li a:eq(0)').attr('href'));

Upvotes: 1

James Allardice
James Allardice

Reputation: 165941

You don't need to use replaceWith if you want to just change the href. You can simply use attr:

$("a[href='/c/13/latest-products']").attr("href", $("#quiklinks_02").attr("href"));

You may be able to improve the first selector as I get the impression the example in your question is not your full code!

Upvotes: 2

Related Questions