hello i would like to hide the elements applying an display= ‘none’ to the function but when I do it really dosn’t work
js
function showAll() {
var arrayOfElements=document.getElementsByClassName('hid');
var lengthOfArray=arrayOfElements.length;
for (var i=0; i<lengthOfArray;i++){
arrayOfElements[i].style.display='block';
}
}
function remove() {
var arrayOfElements=document.getElementsByClassName('hid');
var lengthOfArray=arrayOfElements.length;
for (var i=0; i<lengthOfArray;i++){
arrayOfElements[i].style.display='block';
}
}
I got it working, it had to do with the way JSFiddle handles JavaScript. Make sure you put the code at the end of the body tag, and that it’s not wrapped with any function like window.onload.
Note that each object can have only oneon-event handler for a given event (though that handler could call multiple sub-handlers). This is why addEventListener() is often the better way to get notified of events, especially when wishing to apply various event handlers independently from each other, even for the same event and/or to the same element.
There are other reasons too, like using event bubbling, but it’s kind of rare to use event bubbling.