I have a <div>
block with some fancy visual content that I don't want to change. I want to make it a clickable link.
I'm looking for something like <a href="…"><div> … </div></a>
, but that is valid XHTML 1.1.
I have a <div>
block with some fancy visual content that I don't want to change. I want to make it a clickable link.
I'm looking for something like <a href="…"><div> … </div></a>
, but that is valid XHTML 1.1.
You can give a link to your div by following method:
This is the best way to do it as used on the BBC website and the Guardian:
I found the technique here: http://codepen.io/IschaGast/pen/Qjxpxo
heres the html
heres the CSS
The cleanest way would be to use jQuery with the data-tags introduced in HTML. With this solution you can create a link on every tag you want. First define the tag (e.g. div) with a data-link tag:
Now you can style the div however you want. And you have to create also the style for the "link"-alike behavior:
And at last put this jQuery call to the page:
With this code jQuery applys a click listener to every tag on the page which has a "data-link" attribute and redirects to the URL which is in the data-link attribute.
I pulled in a variable because some values in my link will change depending on what record the user is coming from. This worked for testing :
and this works too :
You can make surround the element with a href tags or you can use jquery and use
My smarty pants answer:
"Evasive answer to: "How to make block level element a hyperlink and validate in XHTML 1.1"
Just use HTML5 DOCTYPE DTD."
Didn't actually hold true for ie7
onclick="location.href='page.html';"
Works IE7-9, Chrome, Safari, Firefox,