473,395 Members | 2,079 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,395 software developers and data experts.

Can a DIV change it's parent element?

dd
I need to know whether an element can move itself to a new parent
within the DOM. I can't find any function that offers me such an
ability. Here's an example of a hierarchy:

-body
....div 1 (parent == body)

.... div 2 (parent == body)
.... ... div 3 (parent == div 2)
.... ... ... div 4 (parent == div 3)
What I'd like to do is allow code to change div 4 so that it no longer
has div 3 and div 2 in its parent hierarchy. I'd like it to be in the
same state as div 1, having document.body as its parent.

By having those div 2 and 3 in it's parent hierarchy it's limited by
them in terms of Zindex (even if div 4 sets it's own zindex to 9999999,
it's really only as high as div 3 and div 2). There are also other
potential CSS issues I'm trying to avoid. I'm not expecting a positive
answer here but I figured I'd try.

What I want to try and avoid is creating a new DIV at the body level
because I don't want (IE) to have to wait for document.readyState ==
complete.

Jan 8 '07 #1
2 33552
dd wrote:
I need to know whether an element can move itself to a new parent
within the DOM. I can't find any function that offers me such an
ability.
Use the Node interface's appendChild method:

<URL: http://www.w3.org/TR/DOM-Level-2-Cor...ml#ID-184E7107 >

Wrapped in a simple function:

function setParent(el, newParent) {
newParent.appendChild(el);
}

Here's an example of a hierarchy:

-body
...div 1 (parent == body)

... div 2 (parent == body)
... ... div 3 (parent == div 2)
... ... ... div 4 (parent == div 3)
Using the function above, and presuming div 4 has id=div4:

setParent(document.getElementById('div4'), document.body);
or just:

document.body.appendChild(document.getElementById( 'div4'));

>

What I'd like to do is allow code to change div 4 so that it no longer
has div 3 and div 2 in its parent hierarchy. I'd like it to be in the
same state as div 1, having document.body as its parent.
Done, see above.
>
By having those div 2 and 3 in it's parent hierarchy it's limited by
them in terms of Zindex (even if div 4 sets it's own zindex to 9999999,
it's really only as high as div 3 and div 2). There are also other
potential CSS issues I'm trying to avoid. I'm not expecting a positive
answer here but I figured I'd try.
In regard to CSS issues, you should discuss those at
comp.infosystems.www.authoring.stylesheets:

<URL:
http://groups.google.com.au/group/co...ng.stylesheets
>
--
Rob

Jan 8 '07 #2
dd
Thanks Rob, I'd figured I could do that, but what I didn't emphasize
enough in my question (I see now) is the issue of doing stuff like this
before document.readyState == "complete" on IE. Do you think that it's
helpful that this isn't creating any new elements, instead it's just
moving one around within the DOM? I'm not sure if that distinction
makes a difference when it comes to IE not liking certain DOM
manipulations before it's completed loading.

Jan 8 '07 #3

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

Similar topics

1
by: Paul Gobée | last post by:
What is the parent element of a button (IE6 on Win, transitional mode)? Is it the BODY, the browser default stylesheet, or something else? Contra "body is parent-element": - Buttons with no...
3
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following...
1
by: MSNews | last post by:
I am new to ASP.NET and have found these context errors in the HTML for the ASPX pages, the site/pages work fine. Can anyone explain why these warning are coming up? Regards
1
by: Manuel Canas | last post by:
Hi there, I'm having a hard time figuring out why is this happening. The problem is a couple of variables are not getting properly initialized when I load a FormX from it's parent form. I...
7
by: David | last post by:
Hi, I'd really appreciate any help. Im trying to change a label over and over again. I can change it the first time, by using the following code, however it never works again, how can i do this...
2
by: mjansen.merge.emed | last post by:
Is there a way to override inline within the <bodya style of an element but not do it with a style attribute on the element? I know CSS Inheritance works for some styles, but doesn't appear to...
2
by: monomaniac21 | last post by:
Hi all is it possible to get a button in an iframe to change location of parent page? regards marc
1
by: libsfan01 | last post by:
Hi all is it possible to get a button in an iframe to change location of parent page? regards marc
1
by: grossespinne | last post by:
Hi guys! I have been looking for a PHP5 class like SimpleXMLElement with the additional feature of being able to reach the parent of its element node. For example consider the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.