Categories:

JavaScript Kit > JavaScript Reference > Here

Link Object (same as Area)

Last updated: June 20th, 2004

Each link on your page is represented by a corresponding link object in JavaScript, with events and properties as described below. You may also loop through every link on your page via the links collection:

document.links[] //links collection
document.links.length //the number of links on your page

Related Tutorials

Events

Events Description
onClick Code is executed when user clicks on link. Return false to disable link. Example(s)
onDblClick Code is executed when user double clicks on link.
onMouseDown Code is executed when user holds mouse down over link.
onMouseUp Code is executed when user releases mouse from link.
onMouseOver Code is executed when user moves mouse over link. Example(s).
onMouseOut Code is executed when user moves mouse out of link.

Properties

Properties Description
 

We will use the link "http://www.mysite.com/good.htm#section2" as basis below to explain the various properties.

hash Specifies the anchor portion of the link. (ie: "section2").
host Specifies the host and domain name of a network host. (ie: www.mysite.com).
hostname Specifies the hostname portion of the link (ie: www.mysite.com).
href Specifies the entire link.
pathname Specifies the path name of the link (ie: /good.htm).
port Specifies the port portion of the link.
protocol Specifies the protocol portion of the link (ie: http:).
search Specifies the query portion of the link (ie: ?sort=alpha)
target Specifies the target attribute of the link.

Examples

onClick

<a href="#" onClick="alert('Welcome to JavaScript Kit!'); return false">JavaScript Kit</a>

JavaScript Kit

onMouseover

<a href="http://www.dynamicdrive.com" onMouseover="window.status='#1 DHTML site online'; return true", onMouseout="window.status=''">Dynamic Drive</a>

Dynamic Drive


Reference List

Partners
Right column

CopyRight 1998-2014 JavaScript Kit. NO PART may be reproduced without author's permission.