View Full Version : getElementsByTagName is not a function

01-19-2012, 08:07 AM
today looking through my logs (errors) and one that came up was

element.getElementsByTagName is not a function

from the source

getByAttribute = function(element, strTagName, strAttributeName, strAttributeValue)
var arrElements = (strTagName == "*" && element.all)? element.all : element.getElementsByTagName(strTagName);

Can anyone help me out here?

01-19-2012, 09:07 AM
Can anyone help me out here?
Please provide your rest of the code.

Old Pedant
01-19-2012, 09:14 AM
Clearly getElementsByTagName *is* a function, but it might not be valid for the kind of element you were trying to apply it to.

DEBUG and tell us what kind of element you go the message for.

01-19-2012, 09:15 AM
here it is ,

I thought it was better this way rather than filling up an entire page (line 705 or just ctrl+f it)

Thanks all

Old Pedant
01-19-2012, 09:47 AM
Well, first of all, the code is really old.

element.all was only needed by MSIE 4. (Maybe MSIE 5?) By the time MSIE 6 arrived, getElementsByTagName was there. (Along with getElementById, of course...that appeared in MSIE 5). And "all" was never needed by any other browser.

But as to why you get an error on that code...

Dunno. The only place you call it, you pass body for the element argument.

And that should clearly work.

I don't suppose you can show this in a working online page, instead of just as code?


I notice that when you call the function, your last argument is a regular expression.

But the function is *clearly* expecting just a string for that last argument.

Because it *builds* a regular expression based on the expected string.

This whole thing seems pretty convoluted to me. You really need to find *ALL* the <option>s on a given HTML page so that you can remove them if they have values with a certain pattern?? Surely you know which <select>s might hold <option>s with this pattern and you could more efficiently apply the removal process to only them?

01-19-2012, 10:11 AM
Thaks for the reply, yeah it is abit, i'm planning to rebuild the whole site again this year, after all it was a prototype and that bit of code was the first done a while back.
change after change without really reconfiguring the whole system has had it's toll on it

Thanks for everything really appreciate it