/    Sign up×
Community /Pin to ProfileBookmark

Get the parent element?

Is there any way to find the parent element of an element in HTML with javascript?
Let’s say I have this HTML :

[code=html]
<div>
<div onClick=”alert(this.parentElement.innerHTML)”>Blah blah</div>
</div>
[/code]

…this, upon clicking the div should alert “<div onClick=”alert(this.parentElement.innerHTML)”>Blah blah</div>”. Now, the parentElement property obviously doesn’t exist, but is there any such thing?

Of course I can do this myself pretty easy, but I’m asking if there’s a more simple solution.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangDec 17.2006 — this.[B]parentNode[/B].innerHTML
×

Success!

Help @Znupi 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 4.29,
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,
)...