mercredi 28 septembre 2016

Toggle display with javascript vanilla

How to toggle display with Javascript Vanilla when I click a checkbox.

I tried with only one element and it works but when there is more than one...I put this in my code-->

function OnlyOK(){      
var ul = document.getElementsByClassName('RQ');
        for (i = 0; i < ul.length; i++) {
              ul[i].style.display = 'none';
      }
}

And the case of toggle display(none,block) only one element (1 first element)...This Works!!

function OnlyOK(){  
  var ul = document.getElementsByClassName('RQ');
  ul.style.display = ul.style.display === 'none' ? '' : 'none';
}

I tried getElementsById too! but I prefer to work with class.




Aucun commentaire:

Enregistrer un commentaire