Html – does document.getElementsByTagName work in vbscript

htmlvbscript

Well, it works, it just doesn't produce anything worthwhile:

elems = document.getElementById("itemsTable").getElementsByTagName("TR") 
for j = 0 to ubound(elems) - 1      
   ' stuff 
next

Well, that won't work, apparently elems is an object, not an array like you'd get in that fancy javascript. I'm stuck with vbscript though.

So what do I do to iterate all the rows in a table in vbscript?

Edit: Yes, it's vbscript and it sucks. I don't have a choice here, so don't say "Use jQuery!!".

Best Answer

As you have correctly stated getElementsByTagName does not return an array, hence UBound() will not work on it. Treat it as a collection.

For-Eaching through it should work:

 Set NodeList = document.getElementById("itemsTable").getElementsByTagName("TR") 
 For Each Elem In NodeList
  ' stuff 
  MsgBox Elem.innerHTML
 Next