HTML DOM Link Object


The HTML DOM Link Object in HTML represents the <link> element.

Syntax

Following is the syntax −

Creating a <link> element

var linkObject = document.createElement(“LINK”)

properties

Here, “LinkObject” can have the following properties −

PropertyDescription
crossOriginIt sets/returns the the CORS settings of the linked document
disabledIt sets/returns whether the linked document is disabled, or not
hrefIt sets/returns the URL of the linked document
hreflangIt sets/returns the language code of the linked document
mediaIt sets/returns the media type for the link element tag
relIt sets/returns the relationship between the current and the linked document
sizesIt returns the value of the sizes attribute of the linked document
typeIt sets/returns the content type of the linked document

Example

Let us see an example for Link disabled property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>Link Disabled</title>
<link id="extStyle" rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form>
<fieldset>
<legend>Link-disabled</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="beautify()" value="Disable Styling">
<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 beautify(){
      extStyle.disabled = true;
   }
</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;
}

Output

This will produce the following output −

Before clicking ‘Disable Styling’ button −

After clicking ‘Disable Styling’ button −

Updated on: 30-Jul-2019

186 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements