/    Sign up×
Community /Pin to ProfileBookmark

accessing attributes help

hi i need to access the id element of a div, but s the only info i will have will be the td id so it will look like

[code=html]<div id=”divid”><table><tr><td id=”tdid”></td></tr></table></div>[/code]

now i need to access the div id. i know there is a way to access different elements in xml with parents, siblings, and stuff like that. any idea how i can get that id attribute with just the fact that td id=”tdid”?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 18.2006 — var obj = document.getElementById("tdid");

while ((obj=obj.parentNode).tagName != "DIV"){};

alert(obj.id); // DIV ID
×

Success!

Help @cjm771 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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