Typical. I may have just answered my own question, but haven't tested
whether it is bulletproof or not:
In the .each loop I have placed the following conditional statement:
if ($(this).children().length > 0)
{
alert("This node till has children\n\n" + $
(this).children().length)
return;
}
else
{
...translate it and replace it......
}
This appears to work, but I did find a snag where a <p> tag had a link
inside it. Will have to check for that special case maybe...any other
suggestions?
Joe
www.subprint.com
On May 5, 2:32 pm, Joe <[EMAIL PROTECTED]> wrote:
> Last week I had a question on how to traverse the DOM and find all
> elements that had some text (p, a, li, h1, etc.) so I could manipulate
> it with Google's translation API. Well with some help from the
> community I was able to accomplish this feat.
>
> http://groups.google.com/group/jquery-en/browse_thread/thread/c63da32...
>
> However, I have a bigger problem. Now, when I grab the all proper
> elements:
>
> $a = $(' #container > * ').contents();
>
> And parse thru them to find which ones have text, it does just that
> BUT if an unordered list is within a div and that UL has text it will
> show up not only with the UL, but within the DIV as well.
>
> $a.each(function()
> { ... translate stuff here ..});
>
> So in iteration one, we find the DIV, and then locate any and ALL text
> in the DIV. Quite a bit for the header navigation.
>
> Example Result for Div:
> HOME BUSINESS CONTACT ABOUT
>
> Then the next iteration is the UL, and it finds its text, which is
> basically the same as the DIV's text result.
>
> Example Result for UL:
> HOME BUSINESS CONTACT ABOUT
>
> Then the next iteration is the LI element, which has the proper text
> but,
>
> The next iteration is the A element which is finally the text I
> actually want to translate.
>
> Example Result for LI and A:
> HOME
>
> So my question is how can I traverse down and grab the last child on
> that particular "branch" of the DOM. Surely there's a way to check if
> current node has or does not have a child, but how with jQuery?
>
> Thanks!
>
> BTW, Ariel Fleisler's recommendation from the previous post appears to
> be the best approach, but my pure Javascript mixing with jQuery skills
> are not quite up to snuff to hash that out...