Need a little help in Javascript

I want to get rid of this easy problem. please help me.

I want a function by which all elements with id="abc" will hide (ie. display = ''none") except where class = "q" . Please type the full function please in pure jaascript. I am new in javascript.

Thanks in advance.
Best regards

Please note ID is unique, meaning you can use an ID in one element only.
Instead you should use Class=abc.

for(var i = 0; i < document.getElementsByClassName('abc').length;i++) {
if (!document.getElementsByClassName('abc')[i].classList.contains('q')){
document.getElementsByClassName('abc')[i].style.display = 'none';
} 
} 
1 Like