Do I really need to check if an element exists with jQuery?

后端 未结 5 666
鱼传尺愫
鱼传尺愫 2020-12-24 00:22

I recently had a question about how to correctly check if an element exists with jQuery. I found the answer from here:

https://learn.jquery.com/using-jquery-core/faq

5条回答
  •  滥情空心
    2020-12-24 01:05

    Is more simple to check if exists and , if we want more info from the object we will not receive null object error.

    if (!!$( "#myDiv" )) {
        //do something
    }
    

提交回复
热议问题