From: Chris on
I am trying to get at all the 'a' tags surrounded by a div tag with an
id of 'id'

This doesn't seem to do it, picks up all 'a' tags

links=document.getElementsByTagName(id).getElementsByTagName("a");

Any thoughts?

Thanks,

Chris
From: Martin Honnen on
Chris wrote:
> I am trying to get at all the 'a' tags surrounded by a div tag with an
> id of 'id'
>
> This doesn't seem to do it, picks up all 'a' tags
>
> links=document.getElementsByTagName(id).getElementsByTagName("a");

That should give an error as getElementsByTagName gives you a node list
and that node list does not have a getElementsByTagName method.
So you probably want
document.getElementById('id').getElementsByTagName('a')
If that does not work for you as intended then you need to provide more
details of the browser that does not work with.



--

Martin Honnen
http://JavaScript.FAQTs.com/
From: Chris on
On 21 Jun, 11:49, Martin Honnen <mahotr...(a)yahoo.de> wrote:
> Chris wrote:
> > I am trying to get at all the 'a' tags surrounded by a div tag with an
> > id of 'id'
>
> > This doesn't seem to do it, picks up all 'a' tags
>
> > links=document.getElementsByTagName(id).getElementsByTagName("a");
>
> That should give an error as getElementsByTagName gives you a node list
> and that node list does not have a getElementsByTagName method.
> So you probably want
> document.getElementById('id').getElementsByTagName('a')
> If that does not work for you as intended then you need to provide more
> details of the browser that does not work with.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/

Thanks Martin,

I am working on a tooltip feature and my problem is that I can't
figure out howto only apply the necessary javascript to relevant links
and not every link on page. If I use

document.getElementById('id').getElementsByTagName('a')

this works for the first link I wrap in a tag with an id but not the
rest e.g.

<div id="tooltipthis"><a href="" title="">link</a></div>
<a href="" title="">No tooltip</a>
<div id="tooltipthis"><a href="" title="">link</a></div>

Thanks again,

Chris
From: Martin Honnen on
Chris wrote:

> <div id="tooltipthis"><a href="" title="">link</a></div>
> <a href="" title="">No tooltip</a>
> <div id="tooltipthis"><a href="" title="">link</a></div>

Ids need to be unique in the complete document so what you have above
can't work.


--

Martin Honnen
http://JavaScript.FAQTs.com/
From: Chris on
On 21 Jun, 12:37, Martin Honnen <mahotr...(a)yahoo.de> wrote:
> Chris wrote:
> > <div id="tooltipthis"><a href="" title="">link</a></div>
> > <a href="" title="">No tooltip</a>
> > <div id="tooltipthis"><a href="" title="">link</a></div>
>
> Ids need to be unique in the complete document so what you have above
> can't work.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/

Martin,

Excuse my lack of javascript knowledge...I approach it like a bull in
a china shop.

After a break and some cheese and toast the obvious answer to my
problem was to do getElementByName("tooltip") and work from there.

Thanks again,

Chris
 |  Next  |  Last
Pages: 1 2 3 4
Prev: Writing Arrays To <select> Tag
Next: debugging in aptana