Javascript DOM HTML Link rel Property get

Introduction

Return the relationship between the current document and the linked document:

var x = document.getElementById("myLink").rel;

Click button to return the relationship between the current and the linked document.

View in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" rel="stylesheet" type="text/css" href="style.css">
</head>//from   w  ww. j  av a 2 s  .com
<body>

<h1>I am formatted with a linked style sheet</h1>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myLink").rel;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The rel property sets or gets a space-separated list that defines the relationship between the current document and the linked document.

Property Values

Value Description
alternate an alternative version of the current document
appendix appendix page for the current document
chaptera chapter
contents table of contents for the current document
copyright the copyright/policy for the current document
glossary the glossary page for the current document
help the help page for the current document
icon an icon location
index the index page for the current document
next the next page
offlinea location that contains a path to the CDF file
prev the previous page
search an XML file in Open Search description format
sectiona section in a list of documents
sidebarthe bookmark panel
start the first page (used by search engines to show the first page)
stylesheet the style sheet for the current document
subsection a sub section for the current document

The rel property returns a String representing a space-separated list of relationship types.




PreviousNext

Related