How to check null objects in jQuery

后端 未结 13 891
Happy的楠姐
Happy的楠姐 2020-11-30 17:24

I\'m using jQuery and I want to check the existence of an element in my page. I have written following code, but it\'s not working:

if($(\"#btext\" + i) != n         


        
13条回答
  •  感情败类
    2020-11-30 18:20

    Using the length property you can do this.

    jQuery.fn.exists = function(){return ($(this).length < 0);}
    if ($(selector).exists()) { 
       //do somthing
    }
    

提交回复
热议问题