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

How do I process the whole text(non-id) in javascript?

I want to know that how can I process the whole text of the HTML
document using just the javascript(for example I wanna convert the
whole text as well as HTML to Uppercase).

I know one way of doing it by document.getElementById().innerHTML, but
that will work only when you gave id to all the text in the file.

So tell me some way by which I can access the whole text of html file
using just javascript.

Sep 2 '05 #1
2 1900

pr***********@gmail.com wrote:
I know one way of doing it by document.getElementById().innerHTML, but
that will work only when you gave id to all the text in the file.


IE allows you to serialize the current DOM of any element with
element.outerHTML so you could serialize the root element with
document.documentElement.outerHTML
There could be nodes like DOCTYPE declarations or comments outside of
the root element however which the above does not cover. And it is a
serialization of the DOM tree and not the source as read from a URL or
local file.
Some other browsers like Opera implement outerHTML as well, others like
Mozilla do not although implementing a serialization with script itself
is possible of course as the DOM tree is there.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 2 '05 #2
Ivo
"Martin Honnen" said
pr***********@gmail.com wrote:
I know one way of doing it by document.getElementById().innerHTML, but
that will work only when you gave id to all the text in the file.


implementing a serialization with script itself
is possible of course as the DOM tree is there.


Such as:

function gettext( o ) {
o = o || document.body;
var b, s = '', j = o && o.firstChild, phrase =
/^(abbr|b|big|cite|code|em|font|i|kbd|span|s|samp|s mall|strong|tt|u)$/i;
if( j && o.childNodes.length<500 ) {
for ( ; j !== null; j = j.nextSibling ) {
if( j.nodeType === 3 ) {
s += j.nodeValue || '';
}
else if( j.nodeType === 1 ) {
b = phrase.test( j.tagName ) ? '' : ' ';
s += b + gettext( j ) + b;
}
}
}
return s.replace( /\s+/, ' ' );
}

Other approaches are certainly more efficient, but this is perhaps still
readable. More about nodetypes for example here:
<URL:
http://msdn.microsoft.com/workshop/a...erties/nodetyp
e.asp > (watch for wrap)
Some effort is made to keep space characters around some phrase elements
with the rather voluminous regex in variable "phrase". It 's not the most
elegant part of the script, but prevents words running together.

hth
ivo
http://4umi.com/web/javascript/

Sep 2 '05 #3

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

Similar topics

1
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node, attribute, text, comments etc. from source and write in...
10
by: Andrea | last post by:
Hi everyone, I am in the process of learning javascript and have a question on location.href. Does javascript always require the <script language = "javascript"> (or script...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
4
by: KenH | last post by:
I have a charting applet that has a print method that works just fine. My problem is I am trying to initiate the print method from a javascript routine but it doesn't work. I access my applet...
4
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
60
by: marss | last post by:
Maybe anyone know good free online JavaScript knowledge test? This not exactly a system for testing online required - it may be simply list of questions with variants of answers (I have to prepare...
13
by: DDragon | last post by:
ok here is the problem, i have to forms which have values i wish to be added together i can add together the values in one form all right but im having problems with adding the values of the other...
0
by: atencorps | last post by:
Hello I have the following code but need some help on it. The idea of the code is the main sections ie Service Management are viewable when the page is loaded and by clicking on the main...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.