getelementsbyclassname - getelementbyclassname instead of getelementbyid is not working -


i have read many times can getelementsbyclassname. below works fine if replace classname id, using word classname not work. know why? (i tried on chrome , firefox)

      <script type="text/javascript">         function makedisable(){         var x=document.getelementsbyclassname("myselect");         x.disabled=true         }         function makeenable(){             var x=document.getelementsbyclassname("myselect");              x.disabled=false         }      </script>       <form>         <select class="myselect" id="myselect">         <option>apple</option>         <option>banana</option>         <option>orange</option>     </select>          <input type="button" onclick="makedisable()" value="disable list">         <input type="button" onclick="makeenable()" value="enable list">     </form> 

the function called getelementsbyclassname. plural. returns not element, array of elements have class name.

so if array consists of 1 item, there 1 element in array, still need index it.

 x[0].disabled=true 

instead of

 x.disabled=true 

fiddle


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -