0

JS

$(".row").live("hover",
    function()
    {
        $(".remove").fadeIn();
    }
    );
$(".row").live("blur",
    function()
    {
        $(".remove").fadeOut();
    }
    );

HTML Markup

<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,

  1. to fade in on hover event, image with class .remove (which stands inside hovered .row div) and fade out on blur event.
  2. On .remove click, get parent div's node attribute

JsFiddle

http://jsfiddle.net/tt13/3VG5P/3/

Am I missing something?

4 Answers 4

1
  1. 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.

  1. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Updated my answer with the click event for .remove elements.
1

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();
    }
});​

http://jsfiddle.net/KPQ5h/1/

1 Comment

Very good solution for 1st problem. UP. Now 2nd: On .remove click, get parent div's node attribute. How can I do this?
1

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();
});

2 Comments

But it fades in all .remove at once. I need the one which stands inside hovered div
blur events dont work on div's so try using mouseout, see the edited code pls
0
$(".row").hover(function(){
   $(".remove", this).stop().fadeIn();
}, function(){
  $(".remove", this).stop().fadeOut();
});

try this one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.