user3290332
user3290332

Reputation:

How to make a entire div a hyperlink

I have a div which contains back-ground colour and other styles, inside there is some text that contains hyper link. How would I add a hyper link to entire div so that when a person clicks on a selected div then whatever is attached to the id get executed:

    <div class="className" style="background-color:green;" id="IDName" >
    <a href="#" style="font-weight: bolder;"> Your Text goes here </a>
</div> 

Upvotes: 2

Views: 9990

Answers (3)

ExceptionalException
ExceptionalException

Reputation: 95

<a href="#" > <div>  This is the div wrapped by an anchor. </div> </a> 

Upvotes: 2

Lu&#237;s P. A.
Lu&#237;s P. A.

Reputation: 9739

You can set onclick on the div

<div class="className" style="background-color:green;" id="IDName" onclick="location.href=#" >

Upvotes: 3

Kheema Pandey
Kheema Pandey

Reputation: 10285

you have to add a display:block on a tag. by default a is inline element so by giving a display:block it will behave as a block level element.

Check the DEMO.

a{display:block;}

Upvotes: 5

Related Questions