We know how to set the href attribute of the anchor tag int HTML, but sometimes we may require to set the the href attribute at runtime i.e. for example, when a user provides us a url and we want to set it at runtime. We can do this with the help of jQuery.
Example 1: In this example, using jquery, we set the attr() method to the url entered by the user in the input tag, when user clicks the set href buton.
Example 2: In this example, we replace the anchor tag in the div ‘link’ with another anchor tag to change the href value. This is another way in which we can change the value of the href attribute.
- HTML | <a> href Attribute
- HTML | <base> href Attribute
- HTML | <link> href Attribute
- HTML | <area> href Attribute
- How to get an element by its href attribute ?
- HTML5 MathML href Attribute
- How to set cursor style to pointer for links without href ?
- CompileTime Vs RunTime Resolution of Strings
- How to create a CSS rule or class at runtime using jQuery ?
- HTML | DOM Location href Property
- AngularJS | ng-href Directive
- HTML | DOM Anchor href Property
- HTML | DOM Base href Property
- HTML | DOM Link href Property
- Node | urlObject.href API
- How to make workaround for window.location.href?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.