Reputation: 23240
$(".row").live("hover",
function()
{
$(".remove").fadeIn();
}
);
$(".row").live("blur",
function()
{
$(".remove").fadeOut();
}
);
<div class="row chapter" node="1">
<img class="remove" src="design/images/remove.png">
Sample
</div>
<div class="row chapter" node="2">
<img class="remove" src="design/images/remove.png">
Sample 2
</div>
What I want to do is,
.remove
(which stands
inside hovered .row
div) and fade out on blur event..remove
click, get parent div's node attributehttp://jsfiddle.net/tt13/3VG5P/3/
Am I missing something?
Upvotes: 0
Views: 414
Reputation: 5672
- To fade in on hover event, image with class .remove (which stands inside hovered .row div) and fade out on blur event.
This will toggle the class "remove" within the hovered row.
$('.row').hover(function() {
$(this).find('.remove').stop(true, true).fadeIn();
}, function(){
$(this).find('.remove').stop(true, true).fadeOut();
});
You should also use stop(true, true) to clear the animation queue and end any ongoing animation.
- On .remove click, get parent div's node attribute
$('.remove').click(function() {
var $parent = $(this).parent();
var nodeValue = $parent.attr('node') || "missing-node-value";
console.log("node =", nodeValue); // DEBUG
$parent.slideUp();
});
View demo.
Upvotes: 2
Reputation: 100175
Check the syntax:
(".remove").fadeIn();
//Should be
$(".remove").fadeIn();
Try:
$(this).children(".remove").fadeIn();
Edited: BLUR events dont work on DIVs so you could try using mouseout, like
$(".row").live("mouseout", function() {
$(this).children(".remove").fadeOut();
});
Upvotes: 1
Reputation: 193261
This is a job for CSS, not jQuery. I would use this simple CSS:
.row .remove {
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-ms-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}
.row:hover .remove {
opacity: 1;
}
Demo http://jsfiddle.net/KPQ5h/
If you still want javascript:
$(".row").on({
mouseover: function() {
$(this).find('.remove').fadeIn();
},
mouseout: function() {
$(this).find('.remove').fadeOut();
}
});
Upvotes: 1
Reputation: 429
$(".row").hover(function(){
$(".remove", this).stop().fadeIn();
}, function(){
$(".remove", this).stop().fadeOut();
});
try this one.
Upvotes: 1