html - Changing a DIV class style in JavaScript -


i can change style of div id...

document.getelementbyid('test').style.display = "none"; 

why can't same thing class?

document.getelementsbyclassname('egg').style.display = "none"; 

how change style of class?

thanks

document.getelementsbyclassname returns list of elements class specified. can set display none of first element:

document.getelementsbyclassname('egg')[0].style.display = "none"; 

or loop through list , set each desired effect:

var eggs = document.getelementsbyclassname('egg'); for(var = 0; < eggs.length; i++) {    eggs[i].style.display='none' } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -