html div onclick event

前端 未结 9 1087
渐次进展
渐次进展 2021-02-05 13:23

I have one html div on my jsp page, on that i have put one anchor tag, please find code below for that,

9条回答
  •  既然无缘
    2021-02-05 13:59

    You need to read up on event bubbling and for sure remove inline event handling if you have jQuery anyway

    Test the click on the div and examine the target

    Live Demo

    $(".expandable-panel-heading").on("click",function (e) {
        if (e.target.id =="ancherComplaint") { // or test the tag
            e.preventDefault(); // or e.stopPropagation()
            markActiveLink(e.target);
        }    
        else alert('123');
    });
    function markActiveLink(el) {   
        alert(el.id);
    } 
    

提交回复
热议问题