Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change url with jQuery?

Tags:

jquery

url

Suppose it's in a.html.

How to change url to b.html with jQuery?

like image 768
omg Avatar asked Oct 28 '25 08:10

omg


2 Answers

I assume you want to change the target (href) of a <a> element using jQuery?

$("a#your_id").attr("href", "b.html"); // where `a#your_id` is your selector

Or, you want to change the current location in the browser (redirect someone to another page)?

window.location = "b.html"; // No jQuery required for this!
like image 101
Isaac Waller Avatar answered Oct 30 '25 12:10

Isaac Waller


if your question is how to change existing href=a.html to href=b.html, then this should work ..

$('a[href=a.html]').attr('href', 'b.html');
like image 43
Scott Evernden Avatar answered Oct 30 '25 10:10

Scott Evernden



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!