x

Can I Anchor a Div?

by Sara Williams

Anchors have long been used to link to specific parts of Web pages. An anchor consists of a hyperlink created by anchor tags and an element -- headings, paragraphs, images and divs, to name a few examples -- that contains an ID. As long as a div has an ID, it is usable as an anchor.

Linking to a Div Anchor

The method for creating a link to an anchored element involves setting the “href” attribute of a pair of “” tags to the ID name, prefixed by a hash symbol: Go to My Stuff Go to My Stuff on Page 2 The first link will send the user to the element with an ID of “my_stuff,” so long as it is on the same page that is being viewed in the browser. The second link will load a different page in the browser and jump to the “my_stuff” div.

Video of the Day

Brought to you by Techwalla
Brought to you by Techwalla

More Articles