hide a div if a condition | SoloLearn: Learn to code for FREE!


hide a div if a condition

who can i hide a div if a condition is true

2/15/2019 10:06:48 AM


7 Answers

New Answer




you can try this: document.getElementsByTagName ("div")[0].style.display ='none';




window.onload=function(){ document.querySelector("div").style.display="none"; }


@Muhd Khairul Amirin Bin Yaacob it didn't work this is the error Uncaught TypeError: Cannot read property 'style' of null at window.onload


@Muhd Khairul Amirin Bin Yaacob i do it bro thanks a lot but the problem now is the function is activated just one time because i have two table and 2 messages box .they switch every 5secondes with a toggle function .the message box is showen if the tables both have a "nok" in a column the message box show the name of the customers with status "nok". so when just one table have a "nok" the message box are hidden ; The function i create work but just one time . this is my code https://code.sololearn.com/WD31Xd33L846/#html and thanks a lot


Start learning Angular / Vue / React, they can do these kind of stuff very easily (e.g. v-if, ng-if..)