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. 3 1860
*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(strId, strTxt) {
var objNode = document.getElementById(strId);
if (objNode) {
var objTextNode = document.createTextNode(strTxt);
objNode.appendChild(objTextNode);
}
}
<pre id="myNode" onclick="AppendText('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/
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.getElementById("idPre").childNodes[0].appendData(" some
additional text");
will do the trick.
You can use other DOM 2 CharacterData methods like insertData() to have
more control.
DU
In <ce**********@news.eusc.inter.net> DU <dr*******@hotWIPETHISmail.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.getElementById("idPre").childNodes[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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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).
...
|
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>...
|
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...
|
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,...
|
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...
|
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.
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |