Why does $('#id') return true if id doesn't exist?

前端 未结 6 716
野趣味
野趣味 2020-11-28 13:08

I always wondered why jQuery returns true if I\'m trying to find elements by id selector that doesnt exist in the DOM structure.

Like this:

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 14:02

    This is just how jQuery works.

    $("#something")

    Object 0=div#something length=1 jquery=1.2.6

    $("#nothing")

    Object length=0 jquery=1.2.6

提交回复
热议问题