Solved

Accessing an objects parent object

Posted on 2008-10-29
2
168 Views
Last Modified: 2012-05-05
I have an object, but need to get the handle for that object's parent, for example

<script>
function x(obj){
    obj=obj.parent;
    // do stuff to the parent object
}
</script>
<div><span onmousedown="x(this)">This is a span inside a div</span></div>

In that example, when the function "x" is executed it is passed the handle for the span, but I need the handle for the div that contains the span. Unfortunately what I have does not work, any ideas?
0
Comment
Question by:steveo225
2 Comments
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 125 total points
Comment Utility
You were nearly there:
<script>

function x(obj){

    obj=obj.parentNode;

	alert(obj);}

</script>

<div><span onmousedown="x(this)">This is a span inside a div</span></div>

Open in new window

0
 
LVL 4

Author Comment

by:steveo225
Comment Utility
ah, so close, just missing 'Node'

Thanks a lot
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now