Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting elements by a partial id string in javascript

Tags:

javascript

I have the followng code:

var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
inputs[i].disabled = bDisabled;
}

I need to now add some logic to only disable the the inputs that have and Id of the form "bib*" where bib can be any character. Ive seen other questions where this is done with jquery but I cant use jquery just simple javascript. Any help would be appreciated.

Thanks

like image 224
Diego Avatar asked Jun 15 '09 23:06

Diego


1 Answers

This is pretty basic stuff.

var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
  if(inputs[i].id.indexOf("bib") == 0)
    inputs[i].disabled = bDisabled;
}
like image 54
Matthew Flaschen Avatar answered Oct 24 '22 05:10

Matthew Flaschen