
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Link href Property
The HTML DOM Link href property sets/returns the path/url of a linked document. −
Syntax
Following is the syntax −
- Returning href attribute value
linkObject.href
- Setting href to a string
linkObject.href = string
Boolean Values
Here, “string” can be the following −
booleanValue | Details |
---|---|
path | It defines the absolute/relative path to a document. |
url | It defines the url address of the document to be linked. |
Example
Let us see an example for Link href property −
<!DOCTYPE html> <html> <head> <title>Link href</title> <link id="extStyle" rel="stylesheet" type="text/css" href="style.css"> </head> <body> <form> <fieldset> <legend>Link-href</legend> <label for="WeekSelect">Sales Target Week: <input type="week" id="WeekSelect" value="2020-W13" disabled> </label> <input type="button" onclick="enableWeekInput()" value="Change Sales Target Week"> <input type="button" onclick="changeStyle()" value="Change Style"> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var inputWeek = document.getElementById("WeekSelect"); var extStyle = document.getElementById("extStyle"); divDisplay.textContent = 'Week Input disabled: '+inputWeek.disabled; function enableWeekInput() { inputWeek.disabled = false; divDisplay.textContent = 'Week Input disabled: '+inputWeek.disabled; } function changeStyle(){ extStyle.href = 'anotherStyle.css'; } </script> </body> </html>
In the above example ‘style.css’ contains −
form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; }
In the above example ‘anotherStyle.css’ contains −
form { width:70%; margin: 0 auto; text-align: center; background-color: rgba(0,0,0,0.7); color: white; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; }
Output
This will produce the following output −
Before clicking ‘Change Styling’ button −
After clicking ‘Change Styling’ button −
- Related Articles
- HTML DOM Anchor href Property
- HTML DOM Location href Property
- HTML DOM Base href Property
- HTML DOM Link disabled Property
- HTML DOM Link hreflang Property
- HTML DOM Link rel Property
- HTML DOM Link sizes Property
- HTML DOM Link type Property
- HTML DOM Link Object
- HTML DOM tagName Property
- HTML DOM accessKey Property
- HTML DOM activeElement Property
- HTML DOM name Property
- HTML DOM nextElementSibling Property
- HTML DOM nextSibling Property

Advertisements