1

I have one transparent div with id=1, and I need to pass mouse events to all underlying divs (regardless of class / id) while keeping this transparent div reactive to it's own mouse events.

So selecting underlaying divs by class/id, and pointer-events: none / display: none are not the options.

$('#1').mouseenter(function() {
    $(this).css('background','rgba(0, 120, 255, 0.3)');
});
$('#a').mouseenter(function() {
   $(this).css('background', 'red');
});
$('#1').mouseleave(function() {
    $(this).css('background','rgba(0, 120, 255, 0.2)');
});
$('#a').mouseleave(function() {
   $(this).css('background', '#555555');
});

http://jsfiddle.net/B6SAy/

How can this be achieved in a class/id independent way?

If it means anything, I have only 1 underlying div at the same time, but that div can have any class / id.

jaredk
  • 986
  • 5
  • 21
  • 37
weaponx
  • 135
  • 5
  • 18

1 Answers1

-3

Instead of mouseenter() and mouseleave(), you could try mouseover(), mouseout(), and/or hover(). These links may help:

StackOverflow: Jquery mouseenter() vs mouseover()

Ben Nadel: jQuery Events: MouseOver / MouseOut vs. MouseEnter / MouseLeave

You can also check out the documentation for each function at api.jquery.com.

Community
  • 1
  • 1
jkdev
  • 11,360
  • 15
  • 54
  • 77