ndrix
ndrix

Reputation: 1241

Hyperlink within hyperlink

Probably a silly questions, but I'd like to have a hyperlink withing another hyperlink, much like a

<a href="#somewhere">
  This is the hyperlink,
  <a href="somewhere_else.html">and this is the other one</a>
</a>

Aside from that it's not compliant and all, is there a way of doing this?

*Edit: the outer hyperlink is used by a carousel, and won't take the browser somewhere.

Upvotes: 2

Views: 2897

Answers (4)

Dmitry Shashurov
Dmitry Shashurov

Reputation: 1704

May be you solution:

<form action="http://myhomepage.ru/" method="get">
  <a href="http://myhomepage.ru/second">second link within</a>
  <button>first link</button>
</form>

Upvotes: 0

Ed Heal
Ed Heal

Reputation: 59997

Lets think about this. What is the browser suppose to do?

Go to the first hyperlink, or the second one, or both?

If you want the first one, then the second hyperlink is not required.

If you want the second one, then close the first one before and reopen if necessary after closing the second.

If both then write some Javascript to get it to open a new window. for the second hyperlink before loading the first hyperlink.

Upvotes: 2

Ryan Atallah
Ryan Atallah

Reputation: 2987

Anchor tags, just like inline or block level elements, layer up on top of each other when nested such that attributes can be set for different subsets of information or visual space within them. This may be useful if you have a large anchor element functioning as a large button, but want to insert a link to a different location within that button.

Have you tried implementing it? See this jsFiddle proving that nested inline elements work, both with span and anchor tags. Note that the nested element overrides the clickable area subset within the parent element, just as you'd expect it to if you were listening for a hover event.

Disclaimer: While technically this can be done, that doesn't mean that it should be done. Nesting links in particular can result in user confusion and be misleading about what content is pointing to what locations.

Upvotes: 1

Shashank Kadne
Shashank Kadne

Reputation: 8101

You can't nest it, but you can do something I did below..

<a href="somewhere">
  This is the hyperlink,</a>
  <a href="somewhere_else">and this is the other one</a>

Upvotes: 0

Related Questions