JavaScript style.height gives me an error -


i had working on sliding menu.

so debug proposes made button:

<input type="button" style="position: fixed; left:0; bottom:0; width:50px; height:25px;" value="test" onclick="login('logf')" />

and here have login function:

var loginshow = false;   function login(c) {     e = document.getelementsbyclassname(c);     if(loginshow)     {         e.style.height = "0";     }     else     {         e.style.height = "110px";     }     loginshow=!loginshow;  } 

but google chrome gives me error:

bar.js:13 uncaught typeerror: cannot set property 'height' of undefined     @ login (bar.js:13)     @ htmlinputelement.onclick ((index):32) 

getelementsbyclassname returns array-like object of child elements have of given class names. need iterate elements , apply style on each one

var loginshow = false;      function login(c) {    let elements = document.getelementsbyclassname(c);    for(let i=0,l=elements.length;i<l;i++){      elements[i].style.height = loginshow ? "0" : "110px";    }    loginshow = !loginshow;    }
div {    background-color: tomato;    border: 1px solid black;  }
<input type="button" style="position: fixed; left:0; bottom:0; width:50px; height:25px;" value="test" onclick="login('logf')" />    <div class="logf"></div>  <div class="logf"></div>


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -