I’ve got a little issue here. I’ve got a div with h1, h2 and p. I want to make the div into a link, but I can’t just wrap a <a> around a div or h1, h2, p. That’s not the correct way, but what should I do to make the whole div into a link?
Should I make every element into a span? This would require a lot more work
<a href="#" class="link">
<span class="div">
<span class="h1"></span>
<span class="h2"></span>
<span class="p"></span>
</span>
</a>
or should I use javascript:
$('.link').click(function(){
document.location.href='#';
})
Assuming your original HTML looks something like the below, you should add a
dataparameter containing the link to follow when the div is clicked:Then you can attach a
clickhandler to thediv:Finally, make sure to add the
cursorattribute in CSS so it’s obvious that the div is clickable: