开发者

jQuery select "not this and not everything in this"

开发者 https://www.devze.com 2023-02-11 18:50 出处:网络
I got a plugin $.fn.dropDown = function(options){ this.each(function(){ var $this= $(this); $(document).click(function(e){

I got a plugin

$.fn.dropDown = function(options){
    this.each(function(){
        var $this= $(this);
        $(document).click(function(e){
      开发者_如何学JAVA      if($(e.target).not($this) && $(e.target).not($this).find('*')){
                // do stuff
            }
        }); 

    });
}

I want to select "not this and not everything in this" ,so far, that doesn't work.


This should work:

var that = this;
$(document).click(function(e) {
    if( e.target != that && !$.contains(that, e.target) ) {
        // do stuff
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消