Answer the question
In order to leave comments, you need to log in
QuerySelector for multiple elements?
Hello, please tell me how to make the script work for st_img_1, st_img_2, st_img_3, st_img_4. Each one needs a slightly different style. Tried through
<script type="text/javascript">
let section = document.querySelectorAll ('.stall');
window.onscroll = magic;
function magic(){
if (window.pageYOffset > 400) {
section.style.width= '20%'
section.style.margin= '-100px 0 0 -200px'
section.style.transition= '1s ease-in-out 0s'
} else {
section.style.width= '10%'
section.style.margin= '0'
}
}</script>
Answer the question
In order to leave comments, you need to log in
In the section variable, you have an array of nodes that you need to iterate over in a loop, for example, using forEach. And then you will already have an instance of one specific section, and you can already execute your code with it
const elements = [...document.querySelectorAll('.stall')];
for (const section of elements) {
console.log(section);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question