Reputation:
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
Reputation: 95
<a href="#" > <div> This is the div wrapped by an anchor. </div> </a>
Upvotes: 2
Reputation: 9739
You can set onclick on the div
<div class="className" style="background-color:green;" id="IDName" onclick="location.href=#" >
Upvotes: 3
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