469,336 Members | 5,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

getElementsByTagName('#comment') ?

Hi.

I'm trying to get a reference to all comments on particular level of
tree.

lev.getElementsByTagName('#comment') - this expression dosn't work at
all
lev.getElementsByTagName('!') - this works fine only for IE

I prepared something like:
for (_k=0, _l=lev.childNodes; _k<_l.length; _k++)
if (lev.nodeName=='#comment' || lev.nodeName=='!') ...

and works fine but I cannot see the reason, why script should search in
all elements when getElementsByTagName might be working quicker. Does
anybody know, how to solve that?
Cheers.

Sep 1 '05 #1
2 1945

X t l a n wrote:
I'm trying to get a reference to all comments on particular level of tree.

lev.getElementsByTagName('#comment') - this expression dosn't work at all
lev.getElementsByTagName('!') - this works fine only for IE
getElementsByTagName has that name as you can find element nodes that
way and not comment nodes so the loop below is fine but simply check

for (_k=0, _l=lev.childNodes; _k<_l.length; _k++)


if (lev.nodeType == 8)


--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 1 '05 #2
> way and not comment nodes so the loop below is fine but simply check
for (_k=0, _l=lev.childNodes; _k<_l.length; _k++)

if (lev.nodeType == 8)


Under ie < 6 comment type is always 1 like for normal node that's why I
check it the way like:
if lev.nodeName=='#comment' ||lev.nodeName=='!')

Thx.

Sep 2 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.