Click to See Complete Forum and Search --> : getElementByName parameter


Xeel
May 12th, 2009, 02:15 PM
Hello everyone

Just for example, instead of using MS's mynode.all to get a collection of all the elements inside some node we use mynode.getElementsByTagName("*").
I am wondering: is there a simple and short way to get desired element by its name using name pattern (something like getElementsByName("myName*") for ex.)?

Thanks in advance =)

P.S. Please, don't offer iterations through the elements with name comparison... :p

PeejAvery
May 12th, 2009, 04:14 PM
Of course there is...

document.getElementsByName()

Remember that multiple elements can have the same name. Therefore, this will return an array, not just the actual element object.

Xeel
May 12th, 2009, 04:26 PM
Of course there is...
Khmm, khmm...
LOL! Ok, my mistake I should have foreseen this... =)
But I wonder... How could you, after all this time, even assume this...

Look at this thread title... See anything there? Ok, ok, I've just missed 's' there (quick typing, you know...) :D

Just kidding. I know this method. My question was about its parameter. Or any other similar solution using some other method.

PeejAvery
May 12th, 2009, 04:35 PM
We all make mistakes...I just read your post too fast.

The correct answer is no. No wildcards exist in this circumstance. You are going to have to walk the DOM recursively toget this, or weed through the arrays returned by getElementsByName.

Xeel
May 12th, 2009, 04:50 PM
:sick:

Will write my own method then...