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

append a child as the first node

178 100+
Hi All,

Im sure its possible, every time I create a new element and add it to a node it becomes the last child.
a=appendChild(object);


How do I append a child to be the first node?
Jul 8 '08 #1
1 34184
mrhoo
428 256MB
This code inserts a new p as the first child node of the first div in the document.
Expand|Select|Wrap|Line Numbers
  1. var who=document.createElement('p');
  2. var pa= document.getElementsByTagName('div')[0];
  3.  
  4. if(pa.firstChild) pa.insertBefore(who,pa.firstChild);
  5. else pa.appendChild(who);
Jul 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: martin.tschofen | last post by:
How do I select only the first node from a for-each loop that contains a the element "photo". the following xsl finds all "art" elements that have a "photo" element. The problem is that I only...
7
by: fremenusul | last post by:
I know I have been asking LOTS of xml questions and I really apprecaite all the help. Here is my XML file <?xml version="1.0" encoding="utf-8" ?> <products> <!-- Repeat the structure below...
0
by: hzgt9b | last post by:
Using visual studio .NET 2003, VB: I'm experiencing an issue with a TreeView object when it gets focus - the first root node in the tree always gets selected when the control gets focus - even if...
3
by: Tony Young | last post by:
Hi, I am very interested to know which one of the two functions below is used more often by people. The 1st way intends to let B prepare the data and A perform the action. The 2nd way intends...
2
by: IcedDante | last post by:
Working with a sorted group, the inability to use following-sibling (which uses Document Order) and convert an RTF (not avaible with the Parser that we are using) hampered our ability to solve the...
0
by: fredrik | last post by:
Hi! I have a problem with reading a xmlfile from a url. I am confused by the long loading time of the first node. When the first node has been loaded, the rest of the nodes is parsed very fast. ...
8
by: ramprat | last post by:
Hi All, I'm using Access 2003 and I've noticed that if I try to create an append query I am not able to append data to the first table (alphabetically) in my list of tables. I can change the name...
5
by: goldenteeplanet | last post by:
void reverse( node * & s) { // NOTE: YOU CAN NOT MOVE DATA FROM ONE NODE TO ANOTHER // YOU CAN ONLY MOVE POINTERS FROM ONE NODE TO ANOTHER //...
1
by: GuruPrasadBytes | last post by:
I have two objects and their types listed below in javascript. 1st one is parentNode type IXMLDOMElement 2nd is child Node type IXMLDOMElement parentNode.xml = "<Security/>" childNode.xml =...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...

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.