Apply href-like attribute for elements without

I work on a page where there are several entries contained in different <div>s. Each of them is just a heading associated with the page, an image and a brief description. However, the description may contain arbitrary tags, including tags <a>.

Since this is quite simple, and the actual link is not so big, I made it so that clicking on it would <div>trigger location.href = (link URL). However, this is rather sad, because this browser is unfriendly: for example, in Google Chrome, an average click on one of the above <div>will not open the link in a new tab.

Given that you should not embed tags <a>, is it possible for any element in XHTML to behave like a link without resorting to Javascript?

I am using XHTML 1.1, posted with the appropriate MIME type, and that is the only restriction to which I am bound.

+3
source share
1 answer

Not really, no. Although it is worth reading Eric Meyer thoughts about it. Also, it looks like HTML5 1 includes the ability of any element to become a link, so it might be worth using this doctype instead of xhtml.

It is also worth adding that html 5 allows an element <a>to enclose block-level elements, see:http://www.brucelawson.co.uk/2008/any-element-linking-in-html-5/ , an example taken from the linked page:

Instead:

<h3><a href="story.htm">Bruce Lawson as Obama running mate!</a></h3>
<a href="story.htm"><img src="bruce.jpg" alt="lovegod" /> </a>
<p><a href="story.htm">In answer to McCain appointment of MILF, Sarah Palin, Obama hires DILF, Bruce Lawson, as his running mate. Read more!</a></p>

you can say:

<a href="story.htm">
<h3>Bruce Lawson as Obama running mate!</h3>
<img src="bruce.jpg" alt="lovegod" />
<p>In answer to McCain appointment of MILF, Sarah Palin, Obama hires DILF, Bruce Lawson, as his running mate. Read more!</p>
</a>

Updated to indicate possible inaccuracy

1: , , , , "... , HTML5... , " ( W3C html 5 ), , . , , .

, ... =/

+2

Source: https://habr.com/ru/post/1735756/


All Articles