javascript - Hiding all elements with the same class name? -


i'm trying hide elements same class name (float_form), i'm trying use script below show them (all of float_form class divs hidden). i've looked @ lot of jquery solutions, can't seem make of them work this.

function show(a) {     var e = document.getelementbyid(a);     if (!e)          return true;      if (e.style.display == "none") {         e.style.display = "block"     } else {         e.style.display = "none"     }     return true; } ​ 

edit: sorry if wasn't clear, not intend use jquery(and know not jquery). looking way use javascript recognize repeated classnames not in style= display:none; without compromising show/hide id element since there loop div id key. html div looks below, {item.id} being while loop.

 <div class="float_form" id="{item.id}" style="display: none;">  

vanilla javascript

function toggle(classname, displaystate){     var elements = document.getelementsbyclassname(classname)      (var = 0; < elements.length; i++){         elements[i].style.display = displaystate;     } }  toggle('float_form', 'block'); // shows toggle('float_form', 'none'); // hides 

jquery:

$('.float_form').show(); // shows $('.float_form').hide(); // hides 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -