Thuộc tính rel của Anchor trong HTML DOM trả về thuộc tính rel của một link. Thuộc tính rel mô tả mối liên kết giữa tài liệu hiện tại và tài liệu được liên kết.
Cú pháp
a) Trả về thuộc tính rel
anchorObject.rel
b) Thiết lập thuộc tính rel
anchorObject.rel = "value"
Ví dụ
Dưới đây là ví dụ về thuộc tính rel của anchor HTML DOM:
<!DOCTYPE html> <html> <body> <h1>Ví dụ</h1> <p><a id="anchorExample" rel="Rel Property" href="https://www.examplesite.com/"> Anchor Rel Property</a></p> <p>Click vào nút</p> <button onclick="display()">Click me!</button> <p id="show"></p> <script> function display() { var docs = document.getElementById("anchorExample").rel; document.getElementById("show").innerHTML = docs; } </script> </body> </html>
Kết quả
Ví dụ này sẽ cho kết quả sau:

Click nút “Click me!” để lấy thuộc tính rel:

Giải thích ví dụ:
Chúng ta lấy một anchor tag với rel property để chỉ định loại quan hệ với tài liệu liên kết (https://www.examplesite.com/):
<p> <a id="anchorExample" rel="Rel Property" href="https://www.examplesite.com/">Anchor Rel Property</a> </p>
Tạo nút “Click Me” để thực thi hàm display:
<button onclick="display()">Click me!</button>
Hàm display lấy thuộc tính rel của phần tử với id=”anchorExample”:
function display() { var docs = document.getElementById("anchorExample").rel; document.getElementById("show").innerHTML = docs; }