473,796 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

html DOM : unable to insertBefore a DL node.

I am frustrated. It appears that one can not use insertBefore to insert
an A node before a DL node. Is that really true?

I *am* able to insert before a <p id="hh"> tag, but not before a <dl
id="hh"> tag.

i am able to do a body.appendChil d with no trouble.

Finally, winIE6 pops an error: 'Invalid argument' at the last snip line
below (FF1.5 fails silently):

A snip from my code:

****
var newA = document.create Element("A");

var refObj=document .getElementById ("hh");

//document.body.a ppendChild(newA ); //works fine
document.body.i nsertBefore(new A,refObj);// winIE6 error: 'Invalid argument'
****

Any ideas why this is happening Is it me? or is there some rule I've
not been able to find?

Thanks for any help.

P.S. Same problem if I use "div1", a div wrapper around the dl node,
instead of body node.

emichael b.
Feb 10 '06 #1
2 2012


e michael brandt wrote:

A snip from my code:

****
var newA = document.create Element("A");

var refObj=document .getElementById ("hh");

//document.body.a ppendChild(newA ); //works fine
document.body.i nsertBefore(new A,refObj);// winIE6 error: 'Invalid argument'


You want/need
if (refObj != null) {
refObj.parentNo de.insertBefore (newA, refObj);
}
You always need to call the DOM methods insertBefore and appendChild on
the parent node you want to append to or insert into.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 10 '06 #2
wow! That works perfectly. I read every google hit I could find and
never did I see this. Thanks so much!

emichael

Martin Honnen wrote:


e michael brandt wrote:

A snip from my code:

****
var newA = document.create Element("A");

var refObj=document .getElementById ("hh");

//document.body.a ppendChild(newA ); //works fine
document.body.i nsertBefore(new A,refObj);// winIE6 error: 'Invalid
argument'


You want/need
if (refObj != null) {
refObj.parentNo de.insertBefore (newA, refObj);
}
You always need to call the DOM methods insertBefore and appendChild on
the parent node you want to append to or insert into.

Feb 10 '06 #3

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

Similar topics

0
1266
by: Horny Porno-thologist | last post by:
Hi all, I'm trying to use insertBefore to create opening/closing tags in my XML, but to no avail - it says something like "parent node cannot be accessed". Anyway, this is what I'm trying to do: convert something like this: <?xml= .... etc>
3
10172
by: John Chen | last post by:
I need to use iframe to create a floating frame. But the contents in the iframe is not a external html file. Rather, it will be dynamically created by jsp. How can I set the src attribute to a URL of a dynamically created html contents rather than a static html file. Thanks.
4
9211
by: Caroline | last post by:
Rather than opening a new window, how can I add a text (or HTML code) in the same HTML page, in a specific location? The code I tried is the following: <head> <script language="JavaScript"> function displayText() { document.write("qwertyuiop"); }
5
3362
by: Derek Basch | last post by:
Can anyone tell me why I cant insertBefore() objects that are selected using getElementById()? <html> <head> </head> <body> <p id="heading1"></p>
5
1896
by: ojvm | last post by:
ok. thanks again for the time spend reading this. this code adds 2 controls in html form but it places in top of the form. i want this control1 control2 control1 control2 control1 control2
6
8393
by: J Williams | last post by:
I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application to create a new HTML document by cloning nodes. The function below is called from the axWebBrowser1_DocumentComplete event using: Dim mNewDoc As mshtml.IHTMLDocument3 mNewDoc = NewDoc(axWebBrowser1.Document) Private Function NewDoc(ByVal mInputDoc As mshtml.IHTMLDocument3) As mshtml.IHTMLDocument3
2
8980
by: Janis Papanagnou | last post by:
This is partly a repost that was maybe too buried to be seen. Sorry for that. I thought it would be an easy to be answered question, but I may be wrong... I wanted to _insert_ cloned table row into the same table, and while using appendChild() worked fine insertBefore() - which is what I actually need - resulted in an error. This code works...
4
2231
by: dcrackel | last post by:
I hope there is a simple solution to this, but I've been unable to find it. $dom = new DomDocument(); $dom->load("test.xml"); $test = $dom->getElementsByTagName("test"); $test->nodeValue = "<b>test</b>"; $dom->save("test.xml");
3
2728
by: dotcom | last post by:
hello, i am sending whole javascript code(it is for freezing html header) it works fine eith IE but not firefox scroll bar does not come var divContent = null; var divHeaderRow = null; var divHeaderColumn = null; var divHeaderRowColumn = null; var headerRowFirstColumn = null; var x;
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9063
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.