javascript - Using getElementByClassName to build an object array -


i using getelementsbyclassname collection of tr.

i want iterate through collection , value of textbox in tr.

i cannot use jquery or other framework.

how can done?

var dom = document.getelementsbyclassname('row'); var arr = []; var len = dom.length; (var = 0; < len; i++) {    // foo = value of text box in row     // bar = value of text box in row     var obj = {    quantity: foo,    price: bar    };  arr.push(obj); } 

firstly, it's getelementsbyclassname, 's' -- can more 1 element, name plural.

secondly, getelementsbyclassname not function on it's own, it's method on dom object.

if want elements in document match given class name, have call document.getelementsbyclassname(), not getelementsbyclassname() on own.

so need this:

var dom = document.getelementsbyclassname('row'); 

the elements within dom object has same methods available root document object, can can call dom[i].getelementsbyclassname(), etc.

for example, in order textarea elements within it, dom[i].getelementsbttagname('textarea').

that should going.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -