anchor and link object are sub-objects (or properties) of the document object, they represent an HTML hyperlin.
These objects have not methods, only properties.

1. anchor object

The Anchor object represents an HTML <a> tag. This object allows you to create a link to another document (with the href attribute), or to a different point in the same document (with the name attribute).
You can access an anchor by using getElementById(), or by searching through the anchors[] array of the document object.

anchor object properties

- Example with the value returned by some of these properties:
<a href="" title="Courses Web" id="idl" rel="friend" target="_blank" hreflang="us-en">Free Courses</a>
<script type="text/javascript"><!--
document.write('href - '+ document.getElementById("idl").href+ '<br />');
document.write('text - '+ document.getElementById("idl").text+ '<br />');
document.write('hreflang - '+ document.getElementById("idl").hreflang+ '<br />');
document.write('rel - '+ document.getElementById("idl").rel+ '<br />');
document.write('target - '+ document.getElementById("idl").target+ '<br />');
- The output of the code above:
href -
text - Free Courses
hreflang - us-en
rel - friend
target - _blank

2. link object

The link object represents an HTML link element.
A link element (<link>) is defined in the head section of an HTML document and it defines the relationship between two linked documents.
You can access an anchor by using getElementById().

link object properties

- Example with the value returned by some of these properties:
<title>JS object</title>
<link rel="stylesheet" type="text/css" hreflang="us-en" name="stylesheet" id="stl" href="style.css" />
<script type="text/javascript"><!--
document.write('href - '+ document.getElementById("stl").href+ '<br />');
document.write('hreflang - '+ document.getElementById("stl").hreflang+ '<br />');
document.write('rel - '+ document.getElementById("stl").rel+ '<br />');
document.write('name - '+ document.getElementById("stl").name+ '<br />');
- The result is:
href - style.css
hreflang - us-en
rel - stylesheet
name - stylesheet

Daily Test with Code Example

Which attribute is used in <a> tag for the address of the link?
src href rel
<a href="" title=""></a>
Which CSS property sets the type of the text font?
font-family text-decoration font-size
h2 {
What instruction selects all the <div> tags with class="cls"?
querySelector("div.cls") getElementsByTagName("div") querySelectorAll("div.cls")
var elm_list = document.querySelectorAll("div.cls");
var nr_elms = elm_list.length;       // number of selected items
Indicate the function that can be used to get the sum of values in an array.
array_sum() array_diff() array_shift()
$arr = array(1, 2, 3, 4);
$arr_sum = array_sum($arr);
echo $arr_sum;       // 10
anchor and link object

Last accessed pages

  1. Get the value of the selected /checked checkboxes in a form (23932)
  2. Zuma Deluxe (27238)
  3. JavaScript strip_tags and stripslashes (2385)
  4. Qwop (20723)
  5. The Rise Of Atlantis (5142)

Popular pages this month

  1. Qwop (4729)
  2. Bubbles3 (4343)
  3. Butterfly Kyodai (3092)
  4. Zuma Deluxe (2869)
  5. Backgammon (1464)