Javascript DOM HTML Anchor rel Property get

Introduction

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.

Values of the rel attribute:

Value Description
alternate alternate version of the document, for example, print page
author author of the document
bookmark related document
help help document
licencecopyright document
next next document in a selection
nofollow search engine spider should not follow that link
noreferrer browser should not send a HTTP referer header if the user follows the hyper link
prefetch target document should be cached
prev previous document in a selection
search search tool for the document
tagkeyword for the current document

Return the value of the rel attribute of a link:

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

Click the button to display the value of the rel attribute of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" rel="nofollow" href="https://www.java2s.com/">Examples</a></p>
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related