$('html').click()… anywhere except one element

前端 未结 4 1808
孤城傲影
孤城傲影 2021-02-05 05:52

I have a dynamically appended menu which I am removing if you click anywhere on page including the menu links itself. What I am trying to achieve is to prevent the remove if yo

4条回答
  •  死守一世寂寞
    2021-02-05 06:05

    $('html').click(function(e) {
    
            /* exept elements with class someClass */ 
            if($(e.target).hasClass('someClass')){
                e.preventDefault();
                return;
            }
    
            /* but be carefull the contained links! to be clickable */
            if($(e.target).is('a')){
                return;
            }
    
            /* here you can code what to do when click on html */
    
        });
    

提交回复
热议问题