1
I would like to know a possibility of an algorithm for me to select a DOM in a more dynamic way, without having to use the getElementById
every time.
I would like to select all the elements and manipulate in JS. Can anyone help me in this, please?
<section id="step00" class="slide">
</section>
<section id="step01" class="slide">
</section>
In fact, I’m trying to display and hide the steps with each click. Like Step By Step.
Imagine I have to do all this:
const step00 = document.getElementById('step00')
const step01 = document.getElementById('step01')
const step02 = document.getElementById('step02')
const step03 = document.getElementById('step03')
const step04 = document.getElementById('step04')
const step05 = document.getElementById('step05')
const step06 = document.getElementById('step06')
const step07 = document.getElementById('step07')
const step08 = document.getElementById('step08')
const step09 = document.getElementById('step09')
const step10 = document.getElementById('step10')
const endTutorial = document.getElementById('endTutorial')
function initTutorial() {
showStep00()
}
function showStep00() {
console.log('Inicio o passo 0')
step00.removeAttribute('hidden')
step01.setAttribute('hidden', 'true')
}
function showStep01() {
console.log('Inicio o passo 1')
step00.setAttribute('hidden', 'true')
step01.removeAttribute('hidden')
}
There must be something more dynamic, where when I click a button with onclick="step03"
, for example, all other buttons are hidden.
Select by class, with getElementsByClassName(), thus selecting all at once. Remembering that you will return an array of elements, then you have to go through the array to make the changes.
– Renato Diniz
How do you want to get the element? by click?
– Sam
I will use onclick in HTML to display and hide the Steps()
– Thiago Cunha
I’ll update my case so you can see what I’m trying to do...
– Thiago Cunha