Reputation: 417
With a
tags you can link to content inside the webpage itself, but should you place the content you're linking to inside the a
tag or outside it?
Like this:
<a name="linkToMe"/>
<div id="content">...</div>
or like this:
<a name="linktoMe">
<div id="content">...</div>
</a>
EDIT:
I dont mean
<a href="#id"> <div id="id"> ... </div> </a>
My question is:
<a href="#id"> Link </a>
...
<a name="id"/>
<div> content </div>
or
<a href="#id"> Link </a>
...
<div id="id"> content </div>
Upvotes: 0
Views: 64
Reputation: 1067
Normally content your are linking with a
tag is placed out side the tag. It does not make any sense to place the content within a
tag which is linking the same content.
Place the link where ever you want to place it in page, and give id of content as href attribute. like
<a href= "#thiscontent"> link</a>
then write your else code and place your content according to your design. But give the same id to the content.
<div id = "thiscontent">.......</div>
Upvotes: 1
Reputation: 1418
The way it works is that : when you have a # in the url, the browser takes what is after (an anchor) (for example : test.dev#anchor, it takes anchor) and it scrolls to the element which has the anchor as an id (for example : ....
Therefore, if you want to have a link to a content, you should put it outside :
<a href="#anchor">Link !</a>
...
<div id="anchor">...</div>
Upvotes: 1