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
- How to get an element by its href attribute ?
- HTML | <link> href Attribute
- HTML | <area> href Attribute
- HTML | <base> href Attribute
- Node | urlObject.href API
- AngularJS | ng-href Directive
- CompileTime Vs RunTime Resolution of Strings
- HTML | DOM Link href Property
- HTML | DOM Base href Property
- HTML | DOM Anchor href Property
- HTML | DOM Location href Property
- How to create a CSS rule or class at runtime using jQuery ?
- How to make workaround for window.location.href?
- How to set cursor style to pointer for links without href ?
- HTML | <li> value Attribute
- HTML | low Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.