Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getElementsByClassName & IE8: Object doesn't support this property or method [duplicate]

I know "getElementsByClassName" is not support by IE8. Do you know what can I use instead? I am getting annoying by error

"Object doesn't support this property or method".

The HTML code is:

function sumar() { var elems = document.getElementsByClassName('verdana14 toAdd'); var myLength = elems.length; total = 0; for (var i = 0; i < myLength; ++i) {    if (elems[i].value!="") {        total += parseInt(elems[i].value,10);        }     }  var promedio = total/myLength; parseFloat(document.getElementById('promediocal').value = promedio.toFixed(2)); } 

This the input text that calls the javascript function:

<input name='AE_EA_1_BIV_003_2' type='text' class='verdana14 toAdd' id='AE_EA_1_BIV_003_2' style='width:50px' onChange='sumar()'/> <input name='AE_EA_1_BIV_003_3' type='text' class='verdana14 toAdd' id='AE_EA_1_BIV_003_3' style='width:50px' onChange='sumar()'/> <input name='AE_EA_1_BIV_003_4' type='text' class='verdana14 toAdd' id='AE_EA_1_BIV_003_4' style='width:50px' onChange='sumar()'/> 
like image 309
Jesus Ibarra Avatar asked Mar 05 '12 15:03

Jesus Ibarra


People also ask

What is getElementsByClassName () used for?

The getElementsByClassName method of Document interface returns an array-like object of all child elements which have all of the given class name(s). When called on the document object, the complete document is searched, including the root node.

What is the difference between getElementById and getElementsByClassName?

getElementById() is used to access the DOM elements using their id and getElementsByClassName() is used to access element(s) using their class .

What is the difference between getElementsByClassName and Queryselectorall?

getElementsByClassName('link') // Output : will return all the element with a class "link" but whereas in query selector it will return only one element which encounters first.

How do you use getElementsByClassName in react?

To find all elements by className in React: Use the getElementsByClassName method to get all elements with a specific class. Place your call to the method in the useEffect() hook.


1 Answers

Use document.querySelectorAll('.verdana14.toAdd').

See also my related blog post.

like image 165
Marat Tanalin Avatar answered Oct 05 '22 16:10

Marat Tanalin