Determining whether jQuery has not found any element

后端 未结 4 1304
执笔经年
执笔经年 2020-12-07 21:17

I\'m using jQuery\'s selectors, especially id selector:

$(\"#elementId\")...

How should I determine whether jQuery has found the element or

4条回答
  •  伪装坚强ぢ
    2020-12-07 21:57

    $('#my_selector').length > 0 
    $('#my_selector').get(0) !== undefined
    $('#my_selector')[0] !== undefined
    

    This is the basic, now do whatever you want.

提交回复
热议问题