Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change the target <a href=""> value using javascript?

How to use javascript or jquery to change the href value of a link, and apply only the with a specific class or id?

For example:

<a href="https://new.url.com" class="change-target" id="change-target">

change to "/abc/swimming.html" :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<a href="/abc/swimming.html" class="change-target" id="change-target">

Any idea? Thanks a lot~

>Solution :

Just change the .href property.

document.querySelector("#some-id").href = "https://stackoverflow.com/";
<a href="https://www.google.com" id="some-id">Click me!</a>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading