Is element.querySelector() different from document.querySelector()?

前端 未结 2 1910
[愿得一人]
[愿得一人] 2020-12-12 01:33

Looking through the mdn \"querySelector\" pops up under both sections and yet they both seem to achieve the same ends. Is either one ideal for different situations? ...or ar

2条回答
  •  旧时难觅i
    2020-12-12 01:54

    The only difference is where the query is rooted. element.querySelector only searches the children of element. Because the scope is narrower it's more efficient.

提交回复
热议问题