Link rel Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Link

Description

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

Set the rel property with the following Property Values

Value Description
alternate Linked page is an alternative version
appendix Linked page is the appendix page
chapterRefers to a book chapter
contents Linked page is the table of contents
copyright Linked page is the copyright/policy
glossary Linked page is the glossary page
help Linked page is the help page
icon Refers to an icon location
index Linked page is the index page
next Refers to the next page
offlineRefers to a location that contains an offline document
prev Refers to the previous page
search Refers to an XML file in Open Search description format
sectionLink to a section in a list of documents
sidebarRefers to the bookmark panel
start Refers to the first page (for search engines to show the first page)
stylesheet Linked page is the style sheet
subsection Linked page is a subsection

Return Value

A String, representing a space-separated list of relationship types

The following code shows how to return the relationship between the current document and the linked document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" rel="stylesheet" type="text/css" href="styles.css">
</head>/*from  w  w  w.j ava 2s.c  o  m*/
<body>

<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>

Related Tutorials