HighDots Forums  

Re: table.rows vs. table.getElementsByTagName (+ a regex question)- additional info from OP

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: table.rows vs. table.getElementsByTagName (+ a regex question)- additional info from OP in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: table.rows vs. table.getElementsByTagName (+ a regex question)- additional info from OP - 05-19-2008 , 01:48 PM






[trimmed attribution novel]

eBob.com wrote:
Quote:
"eBob.com" <eBob.com (AT) totallybogus (DOT) com> wrote:
var parentwin = external.menuArguments;
[...]
for (iv in x)
{
var tablerows = x[iv].rows
//alert(tablerows.length + " rows") // results in "'tablerows.length'
is
//var tablerows2 = x[iv].getElementsByTagName("tr") // results in
"Object doesn't
// support this
property or method ??????
As you can see by now at last, pre-commenting is much better than
post-commenting. Your Question Mark key is borken, BTW.

Quote:
for (triv in tablerows)
{
alert("triv is \""+ triv + "\"; outerHTML:" +
tablerows[triv].outerHTML)
This can be written less error-prone and easier legible:

window.alert('triv is "' + triv + '";'
+ ' outerHTML: ' + tablerows[triv].outerHTML);

Quote:
var marray = re.exec(tablerows[triv].outerHTML)
Why not String.prototype.match() instead?

Quote:
//var marray = re.exec("<td align='center'
class='class_18'>Name</td>")
[...]

Sorry, I forgot to specify that I run the script under IE 6.0.
I suppose one can guess that from your using the `external' property.

However, Martin's correct explanation still stands. Iteration over the
enumerable properties of a NodeList object for which the reference is
returned by document.getElementsByTagName("table") yields the `length'
property as well in IE 6. And a number value if implicitly converted
into a Number object does not have a getElementsByTagName() method.

Same with the NodeList object reference that tableRows evaluates to.
tableRows["length"] yields a number, and the Number object it is being
converted to does not have an outerHTML property. The result of the
expression therefore is `undefined', and literally "undefined" when
implicitly converted to string by RegExp.prototype.exec(). So your
Regular Expression can't find a match.

Please trim your quotes as recommended e.g. in the FAQ Notes.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


Reply With Quote
  #2  
Old   
eBob.com
 
Posts: n/a

Default Re: table.rows vs. table.getElementsByTagName (+ a regex question) - additional info from OP - 05-19-2008 , 03:30 PM






Thank you very, VERY much Thomas and Martin! I would have struggled with
this problem for a long, long time without your help.

One loose end ... I have done some more research and learned about
Enumerators. I tried an Enumerator to step through the table rows and it
seems to work. Is there any practical difference between ...

for (var triv = 0, l = tablerows.length; triv < l; triv++)

and ...

var enumTableRows = new Enumerator(tablerows)
for (;!enumTableRows.atEnd();enumTableRows.moveNext())

?

Also, I discovered the problem with my regular expression. After an eyeball
tuneup I saw that document does quite a bit of massaging of the HTML. So my
regular expression, based on the original HTML, didn't have a chance of
working.

Thanks again for your very prompt and thorough help. Bob







Reply With Quote
  #3  
Old   
Martin Honnen
 
Posts: n/a

Default Re: table.rows vs. table.getElementsByTagName (+ a regex question)- additional info from OP - 05-20-2008 , 05:58 AM



eBob.com wrote:

Quote:
One loose end ... I have done some more research and learned about
Enumerators. I tried an Enumerator to step through the table rows and it
seems to work. Is there any practical difference between ...

for (var triv = 0, l = tablerows.length; triv < l; triv++)

and ...

var enumTableRows = new Enumerator(tablerows)
for (;!enumTableRows.atEnd();enumTableRows.moveNext())

?
Enumerator is specific to Microsoft JScript, don't expect that to work
with other browsers or script engines.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.