Force jquery cursor not to run when above children, just parent

I have <a>c <img>inside, and I want something to happen when you hover over <a>that which works, the problem is that if I move the cursor over the image inside, it starts up again.

Is there a way to make it run only when <a>, and not as a child (which is smaller than the parent).

my js:

$('#logo a').mouseover(function() {
        $(this).addClass('active');
        $('div#header-contact').fadeIn();
    });
+4
source share
4 answers

The problem is mouseover event bubbles for ancestor elements, so you can use a mouseenter event that doesn't bubble

Try the mouseenter event

$('#logo a').mouseenter(function() {
    $(this).addClass('active');
    $('div#header-contact').fadeIn();
});
+2

/

event.stoppropagation

$('#logo a').mouseover(function(event) {
        $(this).addClass('active');
        $('div#header-contact').fadeIn();
        event.stopPropagation()
    });

$('#logo a').mouseenter(function() {
    $(this).addClass('active');
    $('div#header-contact').fadeIn();
});
+2
$('#logo a').mouseover(function() {
        $(this).addClass('active');
        $('div#header-contact').fadeIn();
});


$('#logo a img').mouseover(function(event) {
    event.preventDefault();
});
0
source

stop the mouseover event for a child:

$('#logo a').mouseover(function() {
        $(this).addClass('active');
        $('div#header-contact').fadeIn();
    }).children().mouseover(function() {
  return false;
});
0
source

Source: https://habr.com/ru/post/1523486/


All Articles