how to get all chilredn from elemnt on javascript pure:
i have this code:
const selectFaturamento = document.querySelector("div#faturamento");
const optionsContainer = document.querySelector(".options-container");
const optionsList = document.querySelectorAll(".option");
I basically need to get all the elements: .options-container.option
but they are children of my element: select
why do I have other elements that are not children that have the same class
When using document.querySelector
or document.querySelectorAll
, it uses the document
as the parent. If you are looking for children of a specific selector, you can use that one instead of document
to search inside of that node. For example:
const selectFaturamento = document.querySelector("div#faturamento");
const optionsContainer = selectFaturamento.querySelector(".options-container");
const optionsList = optionsContainer.querySelectorAll(".option");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.