I would like to limit this selector, to give me result only from inside a div with id "divId1"
var polys = document.querySelectorAll('polygon,polyline');
How can I do this?
Try the space operator:
var polys = document.querySelectorAll('#divId1 polygon, #divId1 polyline');
See MDN's page on selectors to learn more.
You can call querySelectorAll on the div element instead of the document.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element.querySelectorAll
Sample:
var polys = document.getElementById('divId1').querySelectorAll('polygon,polyline');
Try this:
var el = document.querySelector('#divId1');
var polys = el.querySelectorAll('polygon,polyline');
https://developer.mozilla.org/en-US/docs/Web/API/element.querySelectorAll
var polys = document.querySelectorAll('#divId1 polygon, #divId1 polyline');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With