Is there a 'not found' exception for jquery selector?

后端 未结 4 1461
孤街浪徒
孤街浪徒 2021-01-18 08:56

I just spent \'hours\' with the following scenario: (all back to the basics)

 $(\'#typo\').bind(\'click\' etc ...

I had a typo in the selec

4条回答
  •  半阙折子戏
    2021-01-18 09:41

    The jquery selector returns an array of DOM Elements so if you check the length of it, if it is greater than 0 it found something, if it is equal to 0 it didn't

      if($("selector").length > 0) found;
    

提交回复
热议问题