hide a div if a condition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

hide a div if a condition

who can i hide a div if a condition is true

15th Feb 2019, 10:06 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
6 Answers
+ 10
you can try this: document.getElementsByTagName ("div")[0].style.display ='none';
15th Feb 2019, 12:42 PM
VEDANG
VEDANG - avatar
15th Feb 2019, 1:28 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 5
window.onload=function(){ document.querySelector("div").style.display="none"; }
15th Feb 2019, 10:47 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 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
15th Feb 2019, 11:05 AM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar
+ 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
15th Feb 2019, 2:17 PM
ABDELMOUGHIT GARDAM
ABDELMOUGHIT GARDAM  - avatar