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

+3

hide a div if a condition

who can i hide a div if a condition is true

2/15/2019 10:06:48 AM

abdo

7 Answers

New Answer

+12

https://code.sololearn.com/W6YAY83uqdln/?ref=app

+10

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

+7

https://code.sololearn.com/W0AYJUE9dl06/?ref=app

+5

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

+2

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

+2

@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

0

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