Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change link to another link in Jquery

Tags:

jquery

A site I am working on has links for add to cart I would like to change that link to point to different page how can I achieve this in jquery.

$(document).ready(function() {
    //alert('Welcome to StarTrackr! Now no longer under police …');
    $("a[href='http://www.somesite.com/scAddItem.aspx?action=add&BJID=421&extra=type,journalIssue,volume,2,issue,<web::ISSUE>,npus,$99.00,npcdn,$99.00']").attr('href', 'http://www.live.com/');
});

I am trying this got this idea from here How to change the href for a hyperlink using jQuery but it's not working for me any help is appreciated.

like image 277
Developer Avatar asked Jan 26 '26 10:01

Developer


1 Answers

Use a selector with *:

$("a[href*='scAddItem']").attr('href', 'http://www.live.com/');

The links' href attribute will be changed for any link that contains scAddItem somewhere in its url. You can modify it for your exact string though.

More Readings:

  • XPath selectors
  • attr method
like image 85
Sarfraz Avatar answered Jan 28 '26 02:01

Sarfraz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!