Only detect click event on pseudo-element

前端 未结 10 1852
长情又很酷
长情又很酷 2020-11-22 08:00

My code is:

p {
    position: relative;
    background-color: blue;
}

p:before {
    content: \'\';
    position: absolute;
    left:100%;
    width: 10px;
         


        
10条回答
  •  盖世英雄少女心
    2020-11-22 08:50

    Add condition in Click event to restrict the clickable area .

        $('#thing').click(function(e) {
           if (e.clientX > $(this).offset().left + 90 &&
                 e.clientY < $(this).offset().top + 10) {
                     // action when clicking on after-element
                     // your code here
           }
         });
    

    DEMO

提交回复
热议问题