I show a bunch of messages from users on the page. I have a main parent div with the class name "posts", and each post is displayed in a div with the class name "row" inside it. So there are a lot of div.row inside div.posts. Everyone looks like this.
<div class="row clearfix">
<div class="left-column">
<img src="..." title="" />
</div>
<div class="main-column">
<div class="row-text">Post Text...</div>
<div class="row-date">Posted Date...</div>
</div>
<div class="actions-column">
<a href="#">Link</a>
<a href="#">Link 2</a>
<a href="#">Link 3 etc.</a>
</div>
</div>
Using CSS, the action column is set to display: none by default. When the user hovers over the message (div.row), I want to show the action column. My original way to do this was by installing a mouseover even for every line, and that was reflected in the browser and slowed down. I did some research and came across a delegation of events and decided to give it a try. While I can determine which row is targeted, however, I cannot figure out how to target the child-div to the column class of the class.
The code is still ...
$(window).load(function(){
$('.posts').mouseover(function(e){
var $row, $tgt = $(e.target);
if ($tgt.hasClass("row")) {
$row = $tgt;
} else {
if ($tgt.parent().parent().hasClass('row'))
$row = $tgt.parent().parent();
else if ($tgt.parent().hasClass('row'))
$row = tgt.parent();
else
return false;
}
});
$('.posts').mouseover(function(e){
var $row, $tgt = $(e.target);
if ($tgt.hasClass("row")) {
$row = $tgt;
} else {
if ($tgt.parent().parent().hasClass('row'))
$row = $tgt.parent().parent();
else if ($tgt.parent().hasClass('row'))
$row = tgt.parent();
else
return false;
}
});
});
source
share