Whole div clickable except

I use CSS-Tricks script, which is pretty simple, except that my script includes a small complex area :)

script:

$(".myBox").click(function(){
   window.location=$(this).find("a").attr("href");
   return false;
});

This works fine except for my DIV. I have a space containing an icon that should trigger a tooltip, but not connected anywhere (already works fine).

My question is: Is it possible that the above script to make the entire DIV clickable EXCEPT when the child interval falls?

Thank!

+3
source share
3 answers

In your hint code, you can stop clicking the bubbles using event.stopPropagation()like this

$(".myBox span").click(function(e){
  e.stopPropagation();
  //show tooltip
});

click .myBox <div> <span>, , .click() / .

+7

:

$(".myBox").click(function(e){
    if (e.target.nodeName.toUpperCase() !== 'SPAN') {
        window.location=$(this).find("a").attr("href");
        return false;
    }
 });

, , , , . , () - .

0

, , span div? span div, , div. :

<span style="position:relative;top:-20px;left:-20px">Icon</span>
<div> Do your div stuff here </div>

. , z- 1 2 , . , , div , ; . , !

0
source

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


All Articles