user2602766
user2602766

Reputation: 171

How do I use an anchor and a hyperlink on the same text?

So I have a box on the right side of the page which when clicked on different titles will take to different news articles on the page though I also have it so when articles within the website titles are clicked upon on the page that they will be taken to the source. At the moment though neither are working what is going wrong?

html

<a name="Anchor1"><a href="http://newsarticle.com">News Article</a></a>

Upvotes: 0

Views: 64

Answers (3)

steveax
steveax

Reputation: 17743

Simply add an id attribute to the link:

<a id="foo" href="http://newsarticle.com">News Article</a>

Then link to it like this:

<a href="#foo">link to foo</a>

Upvotes: 1

user3077828
user3077828

Reputation:

Use id attribute inside the link to have the same effect as name attribute

<a id="Anchor1" href="http://newsarticle.com">News Article</a>

Upvotes: 1

Joke_Sense10
Joke_Sense10

Reputation: 5412

  • Nested <a> elements are forbidden in HTML syntax.
  • Browsers effectively enforce this restriction in their parsing rules.

Example:

if you have a link ,

 <a href="a.html">a<a href="b.html">b</a>c</a>

Browsers will parse it as,

<a href="a.html">a</a> <a href="b.html">b</a> c

Reference: Nested links are illegal.

Upvotes: 0

Related Questions