Anchor rel Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

The rel property sets or gets the value of the rel attribute of a link.

The rel attribute sets the relationship between the current document and the linked document.

Set the rel property with the following Property Values

Value Meaning
alternate An alternate version of the document (such as print page, translated)
author The author of the document
bookmark A related document
help A help document
licenceCopyright information for the document
next The next document in the same selection
nofollow "nofollow" is used by Google to specify that the Google search spider should not follow that link
noreferrer browser should not send a HTTP referer header if the user follows the hyperlink
prefetch the target document should be cached
prev The previous document in the same selection
search A search tool for the document
tagA keyword for the current document

Return Value

A String, representing the relationship between the current document and the linked document

The following code shows how to Return the value of the rel attribute of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p><a ref='search' id="myAnchor" href="https://www.java2s.com">java2s.com</a></p>

<button onclick="myFunction()">get the value of the rel attribute of the link</button>

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

<script>
function myFunction() {//w w w  .  j  a va 2 s.c  o m
    var v = document.getElementById("myAnchor").rel;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials