/    Sign up×
Community /Pin to ProfileBookmark

Can’t get true lastChild in node

I have a page where I am trying to put ids on certain elements. I was able to do this with IE, but Firefox is giving me trouble.

Basic layout of where I’m having problems…
Starting with the 2nd row <TR> in a table.
Row has 3 detail <TD> elements.

The 1st td has one entry that is an image <img>.

The 2nd <td> has a ton of content including <div>, <table> and more <img>.
The 3rd (last) has one entry that is an image <img>.

I can get to the 1st and 2nd <td>, but it stops there. No matter what I try I can’t not make my way to the 3rd one.

Trying childNodes returns an array with length of 4, (#text, <td>, #text, <td>). It stops at the 2nd <td> and does not find the last #text or <td>.

Using lastChild points to the 2nd <td>.

The DOM Inspector shows all 3 <td> elements. Why can’t I traverse to the last one?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangJul 10.2007 — Try using the HTMLcollection to access the elements; it's easier.

If you still have problems, show the complete document or give a link.
Copy linkTweet thisAlerts:
@KorJul 10.2007 — I would have used rather the [B]getElementsByTagName()[/B] method...
×

Success!

Help @ajbill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...