In the scenario shown in the code below, how can I allow the user to click anywhere on div.post
, instead of precisely on one of the the actual a
elements?
<div class="post" style="padding: 20px; background-color: transparent;">
<div class="thumbnail" style="float: left; background-color: #ccc;">
<a href="http://...">
<img src="http://...">
</a>
</div>
<div class="title" style="float: right;">
<a href="http://...">title</a>
</div>
</div>
I also need to highlight the complete div.post
on mouseover, which I currently do using:
[EDIT: Thx to your answers, I have replaced the following by CSS instead of the jQuery]
$("div.post").hover(
function() {
$(this).css("background-color", "#333");
$(this).find("div.thumbnail").css("background-color", "#333");
},
function() {
$(this).css("background-color", "transparent");
$(this).find("div.thumbnail").css("background-color", "#ccc");
}
);
EDIT: Solutions will be preferred that:
- use CSS instead of jQuery
- validate as XHTML 1.0 Strict
- do not wrap an
a
around adiv
- do not involve an empty
a
So far, I consider ArVan's solution to be the best (see my comment there).