+ 2

How to execute if statemen for many elements

For example i have 100 paragraf <p>0</p> <p>0</p> <p>0</p> <p>0</p> ..... <p>0</p> And i want to execute all those paragraphs using if statement like this : "" if all the paragraphs.innerHTML = 0 then...."" Can someone help me?? #javascript

10th Sep 2019, 7:39 PM
Bee David
Bee David - avatar
2 Answers
+ 3
//paragraphs should be an array of all paragraphs var result = true; for(var i=0;i<paragraphs.length;i++){ if(parseInt(paragraphs[i].innerHTML) != 0){ result = false; break; } } if(result){ //all are 0 }else{ //not all are 0 }
10th Sep 2019, 8:02 PM
Anton Böhler
Anton Böhler - avatar
+ 4
you coud do it this way: var allZeroes = true; parag = document. getElementsByTagName("p"); for ( i = 0 ; i < parag. length ; i++) { if (parag. [i].innerHTML ! == 0){ allZeroes = false; break; } } if(allZeroes) { }
10th Sep 2019, 8:07 PM
Bahha┣
Bahha┣ - avatar