473,412 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

get parent ID in nested script

If I have code that looks like this:

<div id="myID">
<script type="text/javascript">
var foo = function() {
// refer to the id myID here
};
</script>
</div>

how can the function "foo" reference the parent container DIV's id
without me having to hard code it?

Andrew Poulos
Jun 27 '08 #1
2 2703
Andrew Poulos wrote:
<div id="myID">
* *<script type="text/javascript">
* * *var foo = function() {
* * * *// refer to the id myID here
* * *};
* *</script>
</div>

how can the function "foo" reference the parent container DIV's
id without me having to hard code it?
I don't think this is possible in an OO-model like javascript. The
code itself is not part of the DOM.

One workaround is to perform an XMLHttpRequest to the same page,
filter on '// refer to the id myID here' and fetch the ID of its
parent tag. You might classify this as hard code.

--
Bart
Jun 27 '08 #2
Andrew Poulos wrote:
If I have code that looks like this:

<div id="myID">
<script type="text/javascript">
var foo = function() {
// refer to the id myID here
};
</script>
</div>

how can the function "foo" reference the parent container DIV's id
without me having to hard code it?
Andrew Poulos
I don't know if it would be suitable in your case, but you could
document write a marker DIV that you could search for and get it's
parentNode.

<div id="myID">
<script type="text/javascript">
var foo = function() {
// refer to the id myID here
var theDiv = document.getElementById("mymarker").parentNode;
};
document.write("<div id='mymarker'></div>");
</script>
</div>
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve | last post by:
Hi, I have a nested class declaration such as: class A: def __init__(self): self.var = "A's variable" # end def class B:
5
by: Paul | last post by:
Hi all, Here is what I am trying to do. I have a parent class calling a child class. when one function in child class is called, i need to call parent class' function. How can I get parent class'...
1
by: Hazz | last post by:
I have 5 tables in SQL Server. Each with the following design and a sample chain of the relationships from the root (WRL - World) UUS is the 'Code' of the first table and it is the 'Parent' value...
1
by: Roy | last post by:
How is it done? BTW, I'm reposting this here, as the datagrid newsgroup appears functionally comatose... I have a nested datagrid setup. When one updates the child grid using edit, it also...
2
by: Roy | last post by:
Ok, this is incredibly annoying. Below I have an ImageButton and it's ImageButton_Click sub. See the 6 response.writes? The output for them is displayed below in asterisks. Question: What part of...
1
by: Yuk Tang | last post by:
Leading on from a recent topic, "How does child class access parent's variables", I would like to ask, what's the most elegant way of changing a parent/grandparent/great-grandparent's property? ...
16
by: Alan Jones | last post by:
Hello everyone, any help would be greatly appreciated. :) What I'm trying to do may not be advisable, but here goes... I want a page named signature.php to appear conditionally as an include...
1
by: mohaaron | last post by:
Can anyone tell me how to get a nested UpdatePanel to update when the trigger control is in the parent UpdatePanel and I don't want to parent to update? I'm trying to change the Visible property of...
1
by: IframeLearner | last post by:
Hi , I am trying to upload a file from a parent.jsp using Iframes. From Parent page. I have to save Subject, Desc, File and file name. to upload the file i am using Iframe. I want the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.