I am looking for way to select element inside of already located element in variable. For example I have selected a container:
JavaScript
x
1
1
let productAttachedFilesModal = document.getElementById('modal_more_information');
I know, that inside are array of a
elements, which I want to select as well. Which method should I use? in jQuery there are method find()
. So I need the analog for JS.
Or I need to use DOM method again? Like this:
JavaScript
1
1
1
let listOfLinks= document.getElementById('modal_more_information > a');
Advertisement
Answer
There are several ways:
JavaScript
1
6
1
let anchors = productAttachedFilesModal.getElementsByTagName("a");
2
3
let anchors = document.querySelectorAll("#modal_more_information > a")
4
5
let anchors = productAttachedFilesModal.querySelectorAll("a");
6