Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would you want an anchor tag that is not a link? (no href attribute?)

The Issue

I have read a couple older SO posts researching info on the anchor pseudo classes, and keep coming across confusion between "a" vs "a:link" and when and why you would use either. In the most common reason I've seen it is often stated that "a" would style links like

<a name="something">

My Questions

  1. I'm just curious if anyone can explain WHY you would want to do something like that?
  2. I've read that maybe it has something to with JavaScript targeting, but with HTML5/CSS3 and libraries like jQuery is this even a valid technique to use anymore?
  3. In what instances would using an anchor tag that is not a link (i.e., doesn't have an "href" attribute) be #BestPractice, or is this method completely deprecated?
like image 362
Eric Hepperle - CodeSlayer2010 Avatar asked Aug 10 '16 22:08

Eric Hepperle - CodeSlayer2010


1 Answers

That can be used for in-page targeting of elements (e.g. to scroll to a certain point):

<a name="table-of-contents"></a>
<h1>Table of Contents</h1>
...
<a href="#table-of-contents">Table of Contents</a>

Though, this is often redundant (and may also take up white space) because elements with IDs can be targeted directly:

<h1 id="table-of-contents">Table of Contents</h1>
...
<a href="#table-of-contents">Table of Contents</a>
like image 58
Ates Goral Avatar answered Sep 30 '22 14:09

Ates Goral