/    Sign up×
Community /Pin to ProfileBookmark

how do i get to the parent ?

i have this:

[QUOTE]

<li class=”open” id=”navlist1_1″><a href=”#” onclick=”navlist(‘navlist1_1’);”>text</a></li>

[/QUOTE]

can i do it without the ID ?
to relate to the “parent” (li) somehow from within the function?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 21.2005 — Yes

viewing from the [B]a[/B] tag, [B]li[/B] (as an object) is related as [B]this.parentNode[/B]
Copy linkTweet thisAlerts:
@ofirauthorNov 21.2005 — EXCELLENT !!!

it works.. me happy !

but wierd..

this works:
<li><a href='#' onclick="navlist1(this);">text</a>[/QUOTE]

but this is NOT:
<li><a href='javascript:navlist1(this);'>text</a>[/QUOTE]

the difference is the first is ONCLICK and the second isnt.
Copy linkTweet thisAlerts:
@KorNov 21.2005 — <li><a href='#' onclick="navlist1(this);[B]return false[/B]">text</a>

to avoid scrolling up, if page is scrolled


but this is NOT:

Quote:

<li><a href='javascript:navlist1(this);'>text</a>
[/quote]


This should work, but only this way

<li><a href="javascript:void(navlist1(this))">text</a>
Copy linkTweet thisAlerts:
@ofirauthorNov 21.2005 — great !! Thanks !!!

i will use the [B]onclick="navlist1(this);return false"[/B]

but still the other one (the "void") is NOT working
Copy linkTweet thisAlerts:
@KorNov 21.2005 — 
but still the other one (the "void") is NOT working[/QUOTE]

Yes, sorry, I have forgotten that void() is in fact an unary [I]operator[/I], not a real function, so that whithin this syntax, [B]this[/B] returns the window object, not the nested object (as all the operators, if accept argument, the argument belongs to the window object).
×

Success!

Help @ofir 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.25,
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,
)...