473,698 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOM: how to append to node'd contents?


This question refers to the DOM. I would like to dynamically append
some small amount of text to the all-text content of a <pre> node.
I suppose that I could extract the existing content, and replace
the <pre> node in question with a new <pre> node that has the
extended content. But the existing content is longish, and it
seems to me wasteful to rewrite it all just to have a small amount
of text tacked on to the end. Is there a way to simply append the
new text to the node's contents?

TIA,

jill

--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.

Jul 23 '05 #1
3 1880
*J Krugman* wrote:
This question refers to the DOM. I would like to dynamically append
some small amount of text to the all-text content of a <pre> node.
I suppose that I could extract the existing content, and replace
the <pre> node in question with a new <pre> node that has the
extended content. But the existing content is longish, and it
seems to me wasteful to rewrite it all just to have a small amount
of text tacked on to the end. Is there a way to simply append the
new text to the node's contents?


Not sure why you can't append another text node to the pre element?
E.g.:

function AppendText(strI d, strTxt) {
var objNode = document.getEle mentById(strId) ;
if (objNode) {
var objTextNode = document.create TextNode(strTxt );
objNode.appendC hild(objTextNod e);
}
}
<pre id="myNode" onclick="Append Text('myNode', 'It was\r\nthe fact'
+' that the cave was in the middle of Islington and there wasn\'t\r\n'
+'a bus due for two million years.')">Life, the Universe, and Everything
for Sally
Chapter 1
The regular early morning yell of horror was the sound of Arthur Dent
waking up and suddenly remembering where he was. It wasn't just that
the cave was cold, it wasn't just that it was damp and smelly. </pre>
--
Andrew Urquhart
- FAQ: www.jibbering.com/faq/
- Archive: www.google.com/groups?q=comp.lang.javascript
- Contact me: http://andrewu.co.uk/contact/
Jul 23 '05 #2
DU
J Krugman wrote:
This question refers to the DOM. I would like to dynamically append
some small amount of text to the all-text content of a <pre> node.
I suppose that I could extract the existing content, and replace
the <pre> node in question with a new <pre> node that has the
extended content. But the existing content is longish, and it
seems to me wasteful to rewrite it all just to have a small amount
of text tacked on to the end. Is there a way to simply append the
new text to the node's contents?

TIA,

jill

W3C DOM 2 CharacterData appendData() method is what you're looking for
here and appendData() is supported by almost all browsers (MSIE 5+ Mac
and Windows, NS 6+, Mozilla 1.x, Firefox 0.5+, Safari 1.x, K-meleon
0.7+, Opera 7.x, Galeon 1.x, Konqueror 3.x, etc.) and is a W3C web
standard method.

Assuming you have:

<pre id="idPre"> ... </pre>

then

document.getEle mentById("idPre ").childNod es[0].appendData(" some
additional text");

will do the trick.
You can use other DOM 2 CharacterData methods like insertData() to have
more control.

DU
Jul 23 '05 #3
In <ce**********@n ews.eusc.inter. net> DU <dr*******@hotW IPETHISmail.com > writes:
J Krugman wrote:
This question refers to the DOM. I would like to dynamically append
some small amount of text to the all-text content of a <pre> node.
I suppose that I could extract the existing content, and replace
the <pre> node in question with a new <pre> node that has the
extended content. But the existing content is longish, and it
seems to me wasteful to rewrite it all just to have a small amount
of text tacked on to the end. Is there a way to simply append the
new text to the node's contents?

TIA,

jill

W3C DOM 2 CharacterData appendData() method is what you're looking for
here and appendData() is supported by almost all browsers (MSIE 5+ Mac
and Windows, NS 6+, Mozilla 1.x, Firefox 0.5+, Safari 1.x, K-meleon
0.7+, Opera 7.x, Galeon 1.x, Konqueror 3.x, etc.) and is a W3C web
standard method. Assuming you have: <pre id="idPre"> ... </pre> then document.getEl ementById("idPr e").childNod es[0].appendData(" some
additional text"); will do the trick.
You can use other DOM 2 CharacterData methods like insertData() to have
more control.


Thank you. That was very helpful.

jill

--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.

Jul 23 '05 #4

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

Similar topics

0
1078
by: Marko Faldix | last post by:
Hello, I have got some standard problems still realized with MS xml 4. The following code runs on Windows machines with python and win32com installed. Could you use pyxml or 4suite to make every of these problems work on any machine? The standard problems are:
4
17815
by: Juliano Freitas | last post by:
How can i get the text between the <teste> tags?? >>> xml = """<root><teste> texto </teste></root>""" >>> from xml.dom import minidom >>> document = minidom.parseString(xml) >>> document <xml.dom.minidom.Document instance at 0x4181df0c> >>> minidom.getElementsByTagName('teste') >>> element = document.getElementsByTagName('teste')
3
1169
by: Richard Lewis | last post by:
Hi there, I have an XML document which contains a mixture of structural nodes (called 'section' and with unique 'id' attributes) and non-structural nodes (called anything else). The structural elements ('section's) can contain, as well as non-structural elements, other structural elements. I'm doing the Python DOM programming with this document and have got stuck with something. I want to be able to get all the non-structural elements...
2
2230
by: DaRik | last post by:
Hi, I'm having some difficulties with a menu I'm making. I build up the menu through DOM. I append childnodes to a tree. 2 types of children are possible: url (a hyperlink) and sub (a submap). The tree is thus of a structure main |-url1
8
4281
by: jog | last post by:
Hi, I want to get text out of some nodes of a huge xml file (1,5 GB). The architecture of the xml file is something like this <parent> <page> <title>bla</title> <id></id> <revision> <id></id> <text>blablabla</text>
2
3152
by: James | last post by:
Hello everyone. I've been looking for examples on this: http://www.php.net/manual/en/functi...-appenddata.php but can't really find one. I've got a function that generates a return value in HTML, and need to append that to the body tag of my document. So I've captured the contents of the page with output buffering, and have loaded it into the PHP DOM. I've isolated the body element: ,----
3
2292
by: robert.oschler | last post by:
I have an AJAX driven page where I dynamically add rows to a known table on the page, based on the return document from the AJAX call, using DOM node methods (except for a small snippet of code, see below) .. The code I use to do that is shown below. The code runs fine in FireFox. I can see the newly created table rows and everything looks fine on the page. In Internet Explorer, I don't see any changes to the page after the new nodes...
3
8714
by: mich dobelman | last post by:
Currently my web server supports only php4. I want to know how to parse the xml and get the element value using dom. I thought they have similar function for getting element by id or tag name, so far i haven't find anyting like that except fro PHP5 with Domdocument. Any help is appreciated. $dom = domxml_open_file ('data.xml'); $e_data = $dom->document_element();
7
3296
by: vunet.us | last post by:
I cannot append a node from XML into the HTML dom (textarea field) in IE. But I can for the text input html elements! Is anyone aware of this and what is the possible solution? Thanks.
0
9170
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
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
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...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
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
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.