/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Accessing upper level node

Hi all,
Say for instance you have:

[code=html]
<tr>
<td>Select Terminal:</td>
<td>
<select id=”ddlTerminals” name=”terminals” title=”Terminals”>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>3</option>
</select>
</td>
</tr>
[/code]

and you would like to access the [B]<tr>[/B] tag to apply a style to it (in my case make it invisible) and all you have is the [B]id[/B] for the [B]<select>[/B] tag.

Is there a way to access the [B]<tr>[/B] tag through javascript with only a [B]<select>[/B] id? Basically a way to access an outer tag (or parent tag or whatever it’s called) untill I reach [B]<tr>[/B].

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzAug 31.2006 — document.getElementById('ddlTerminals').parentNode.parentNode
[url=http://www.dynamicsitesolutions.com/javascript/hiding_and_unhiding_table_rows/][b]Hiding and Unhiding Table Rows[/b][/url]
Copy linkTweet thisAlerts:
@arzo2000authorSep 01.2006 — Thank you for your quick response. Actually that was quite helpfull, but what if you're not sure how many nodes are there before you reach the [B]<tr>[/B]?
Copy linkTweet thisAlerts:
@KravvitzSep 01.2006 — You're welcome ?

You could do something like this:
while(el.parentNode.tagName.toLowerCase()!='tr') el=el.parentNode;
×

Success!

Help @arzo2000 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.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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