Answer the question
In order to leave comments, you need to log in
Appearance and disappearance of a block having a class - Native JS and DOM?
Good afternoon. Why did getElementsById work but not class lookup?
Here is the code:
function Aaa(){
// блок исчезновения
var links = document.getElementsByClassName('item');
links.style.display = 'none';
}
function Bbb(){
// блок появления
var links = document.getElementsByClassName('item');
links.style.display = '';
}
// После загрузки документа
window.onload = function(){
document.getElementsByClassName('aaa').onclick = function(){
alert("блок исчезнет");
Aaa();
}
document.getElementsByClassName('bbb').onclick = function(){
alert("блок появится");
Bbb();
}
}
Answer the question
In order to leave comments, you need to log in
and you look in the documentation what getElementById returns and what getElementsByClassName
I give a hint - getElement s ByClassName
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question