[英]How to get all the divs within a div with certain id using querySelectorAll
[英]querySelectorAll - How to only get elements within a certain div
我想限制這個選擇器,只給我一個id為“divId1”的div里面的結果
var polys = document.querySelectorAll('polygon,polyline');
我怎樣才能做到這一點?
var polys = document.querySelectorAll('#divId1 polygon, #divId1 polyline');
嘗試這個:
var el = document.querySelector('#divId1');
var polys = el.querySelectorAll('polygon,polyline');
https://developer.mozilla.org/en-US/docs/Web/API/element.querySelectorAll
您可以在div元素而不是文檔上調用querySelectorAll。
參考: https : //developer.mozilla.org/en-US/docs/Web/API/Element.querySelectorAll
樣品:
var polys = document.getElementById('divId1').querySelectorAll('polygon,polyline');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.