Reputation: 1078
I need a small help replacing the url in a given page.
I am using athis board which uses some external content and it comes with some links like :
"To learn more about this, visit our FAQ Page."
My issue is that The word FAQ has a link in it which points to lets say http://www.xyz.com/faqs
Now I want to do 2 things with it:
I want to change that link to http://www.mydomain.com/faqsection
.
I want the link to open in a new window.
UPDATE:
The actual code is like this :
<a onclick="window.open(this.href); return false;" title="FAQ" href="/postFAQ">FAQ</a>
Page.
I would want to replace the complete "/postFAQ"
part to http://www.mydomain.com/faqsection
.
I am using jQuery in my application, hence is it possible to do this using some jQuery script?
Upvotes: 1
Views: 1086
Reputation: 267049
1) Give your link an id, e.g:
<a onclick="window.open(this.href); return false;" title="FAQ" href="/postFAQ" id="faqLink">FAQ</a> Page.
2) Do the following in Jquery:
$("#faqLink").attr({href :"http://newlink.com", target: "_BLANK"});
Upvotes: 0
Reputation: 816262
You could use the attribute selector:
$('a[href="/postFAQ"]').attr('href', 'http://www.mydomain.com/faqsection');
Upvotes: 1
Reputation: 3175
Assuming your FAQ tag is like this:
<a href="http://www.xyz.com/faqs">FAQ</a>
You can do something like this:
jQuery(document).ready(function(){
jQuery("a").each(function(e){
if(jQuery(this).text() == "FAQ"){//Very bad way!!
jQuery(this).attr({"href":"http://www.mydomain.com/faqsection",
"target":"_blank"});
return;
}
});
});
Upvotes: 1