How can I make it so the user can click anywhere on div.post instead of just on one of the actual a
elements in the code below?
<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 want to highlight the entire div.post
when hovered over by the mouse, which is currently achieved with this jQuery:
[EDIT: Thanks to your feedback, I have switched to using CSS instead of 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: The ideal solutions should:
- utilize CSS rather than jQuery
- be compatible with XHTML 1.0 Strict validation
- avoid wrapping a
div
inside ana
- not involve an empty
a
So far, I find ArVan's approach to be the most effective (refer to my comment there).