user8388693
user8388693

Reputation:

How do you code a div element in html to be a link?

I am trying to create a div element, that when you click it, the div will bring you to a website. My code is below:

<div class="clickme">
<p>Click me to go to somesite.com</p>
<p>Dummy text...................</p>
</div>

Upvotes: 0

Views: 54

Answers (2)

Itay Gal
Itay Gal

Reputation: 10834

While wrapping a <div> with an <a> possible, it's not common.

Most of the time JS is being used, listing to a click event, since the action required is not redirecting to a different page, but to trigger an action without redirecting or including more logic than redirecting.

Upvotes: 1

user8388693
user8388693

Reputation:

Wrap the div in a element

Shown below...

<a href="somesite.com">
<div class="clickme">
<p>click me to goto somesite.com</p>
<p>DUMMY TEXT...........</p>
</div>
</a>

Upvotes: 3

Related Questions