473,509 Members | 2,528 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

redisplaying the body

YAD
How do you make a small change to the body of an html page from an event
handler? If you have a string var, a function that displays it in the
body, and a function that changes it, can you change the var on an event
and then reparse the body of the page but not the head? And if not,
then what?
Aug 10 '06 #1
4 1214
YAD <go******@vapornet.comwrote in
news:eb**********@wildfire.prairienet.org:
How do you make a small change to the body of an html page from an event
handler? If you have a string var, a function that displays it in the
body, and a function that changes it, can you change the var on an event
and then reparse the body of the page but not the head? And if not,
then what?
I'm a JavaScript novice, but how about something like this:

<html><head>
<title>Ch-ch-changes...</title>
<script type="text/javascript" language="javascript"><!--
function showThisText(text)
{
// santity checks left out for clarity...
target = document.getElementById('changeTarget');
// you may also want to do something less brute-force here, too
target.innerHTML = text;
}
--></script>
</head><body>
<div onMouseOver="showThisText('I\'ve been changed!')"
onMouseOut="showThisText('original text')">Mouse over me!</div>
<p>
<div id="changeTarget">original text</div>
</body></html>
Aug 10 '06 #2
YAD
Spurrious Umlaut wrote:
YAD <go******@vapornet.comwrote in
>How do you make a small change to the body of an html page from an event
handler?
target = document.getElementById('changeTarget');
target.innerHTML = text;
Thank you. I didn't see that in the manuals I found online. Mozilla has
it though, at developer.mozilla.org. In the other ones, all I saw was
open(), write(), etc..

Thanks a lot, it's working now.
Aug 10 '06 #3
Hi,

YAD wrote:
How do you make a small change to the body of an html page from an event
handler? If you have a string var, a function that displays it in the
body, and a function that changes it, can you change the var on an event
and then reparse the body of the page but not the head? And if not,
then what?
The modern way to do that is to use DOM level 2 methods. The easiest is
to wrap the string that has to be changed in a span, for example, and
then to use document.getElementById to get the span, and then modify the
text node contained in that span:

var nSpan = document.getElementById( "yourSpanId" );
if ( nSpan
&& nSpan.firstChild
&& nSpan.firstChild.nodeValue )
{
nSpan.firstChild.nodeValue = "Your string";
}

works with this HTML code:

<span id="yourSpanId">This is the original string</span>

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 10 '06 #4
YAD
Laurent Bugnion wrote:
The modern way to do that is to use DOM level 2 methods.
What about document.write? Are we supposed to stop using that?
I don't see it in the level 2 spec. It seems to be superseded by
a bunch of more specific methods. And what about old browsers?
How many are still running that don't support level 2?
Aug 10 '06 #5

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

Similar topics

1
2106
by: Gordon - Adelphia | last post by:
I have a question regarding xhtml. Why, why, why does the ELEMENT <body> allow “unblocked” text. HTML does not (though, most browsers will render). Xhtml (transitional) however allows text nodes...
6
2698
by: Terry | last post by:
I'm real new at this, so this may be a basic question, but I want to get off on the right foot. I thought it would be reasonable to use the following on a page: body { margin: 3em;...
6
7476
by: Patrick | last post by:
Hi I am a newbie struggling a little with css.It is hard to get it right in all browsers, so i decided to read the CSS2 specification on the w3 site. What is the following from the CSS2...
7
3225
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
0
2157
by: Tony Johansson | last post by:
Hello! Here I have two classes these are called Handle and Body and a main. You have the class definition below. Some basic information. In the Handle class is there a pointer to the Body. Each...
1
424
by: Paxton | last post by:
I have a 3 col page with 3 main divs: #leftcontent, #maincontent, #rightcontent. leftcontent (100px) and rightcontent(160px) hold elements that are not needed for print (some images and forms)....
4
1843
by: sadieslc | last post by:
I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what...
1
8775
by: Karch | last post by:
If you run this: string result = "<html><head></head><body>The body</body></html>"; result = retainBody.Replace(result, "$1"); With the following Regex: private static readonly Regex...
0
7233
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
7135
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
7342
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,...
1
7067
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...
0
7505
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...
1
5060
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...
0
3215
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...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
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 ...

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.