Answers for "how to use get Element without document"

3

how to use get Element without document

// You can use querySelector ->

//first get your element with query or getelement
let element = document.getElementById('id');
let element = document.querySelector('#id');

//you can use query on this element to only get element from this element

//with id
let text1 = element.querySelector('#text1');

//with class
let text2 = element.querySelector('.text2');

//other way
let span = element.querySelector('span');

//querySelector will only get the first element found, if you want them all you
//have to use querySelectorAll
Posted by: Guest on August-04-2021

Code answers related to "how to use get Element without document"

Code answers related to "Javascript"

Browse Popular Code Answers by Language