473,406 Members | 2,698 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.

Changing text between <div>'s

Stupid basic question but I find it horribly imposible to find the answer
elsewhere... :-(

I want to have a piece of text in my HTML page and want to be able to change
it in a Javascript function that is called from a button. I think I can use
a

<div id="t"></div>

for this ? Something like

document.t.value="Hello"

should change it into

<div id="t">Hello</div>

I am getting fucking mad at finding these simple things.... Is there a good
intro somewhere ? My thick Oreilly JS book is just too busy with the
complicated stuff somehow :-((

Ton

--
--
Computer museum tonh: http://www.tonh.net/museum - 10.000 visitors !!
GGGallery website generator: http://www.tonh.net/gggallery
Vrij Kunst Centrum : http://www.meesterschap.nu

Jul 20 '05
55 7129
ji*@jibbering.com (Jim Ley) writes:
The same would be true of .chicken or a read only innerHTML that
resulted in no change afterwards. What we want to know is if our
content ended up on the page.


Ah, Doh. *slaps forehead*. Yes, simply testing that you can write
to it, is not sufficient.

You assume that the HTML is normalized when passed through innerHTML.
That is a fair assumption, and correct for the current browsers.

Another method could be to create an element with an id, and then check
whether it becomes part of the document with document.getElementById
(or fallbacks, e.g., document.all, as usual).
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #51
In article <3f*************@news.cis.dfn.de>, ji*@jibbering.com (Jim Ley)
writes:

I was relying on the fact it would be a normalised source, so by
putting in mixed case element names, and extra whitespace in the
elements I was relying that if innerHTML wasn't known, then it would
be the same (it would just be a new property on the DOM element) but
it if it was known it was normalised away.


Just for my own curiosity, do you see any problems with the function I wrote to
check to see if it works?

function insertHTML(elem,newHTML){
tempVar = document.getElementById(elem).innerHTML;
document.getElementById(elem).innerHTML = newHTML;
if (tempVar == document.getElementById(elem).innerHTML) {alert('It failed')}
}

Maybe a different alert message (or another notifying mechanism). I left out
the object detection that should obviously go with it though.
--
Randy
Jul 20 '05 #52
hi************@aol.com (HikksNotAtHome) writes:
Just for my own curiosity, do you see any problems with the function
I wrote to check to see if it works?
I can see the same problem he pointed out in my attempt :)
function insertHTML(elem,newHTML){
tempVar = document.getElementById(elem).innerHTML;
document.getElementById(elem).innerHTML = newHTML;
if (tempVar == document.getElementById(elem).innerHTML) {alert('It failed')}
}


Change "innerHTML" to "chicken" and it appears to work. That is, it only
tests whether there is a writeable property, not whether assigning to it
changes the document structure.
It would succeede in Netscape 4, if the getElementById had worked.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #53
JRS: In article <3f*************@news.cis.dfn.de>, seen in
news:comp.lang.javascript, Jim Ley <ji*@jibbering.com> posted at Sat, 3
Jan 2004 13:07:02 :-
On Sat, 03 Jan 2004 01:59:25 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
You can also (safely, I think) assume that a value gotten from the
innerHTML property can be put back in and give the same result.


The same would be true of .chicken or a read only innerHTML that
resulted in no change afterwards. What we want to know is if our
content ended up on the page.


We want to know if the previous visible content (if any) is removed, if
new content appears, and if new content looks as expected; or if an
error message appears.

We, as authors, can never know, since writing for an unknown browser is
a one-way process. Only if we can run the same version of the same
browser and test it ourselves can we really know.

Our code can never know all of the above; it cannot detect a fatal
error, it cannot read the screen, and it cannot detect a systematic
delusion that the required property is spelt InnerHTML.
ISTM that

<div ID=X><FONT color=red>NO GOOD</font></div>
That should read "All seems well", in lime.

<script ... >
DynWrite('X', '<FONT color=lime>All seems well</font>')

should enable the user to tell whether things are at least to some
extent working.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #54
In article <is**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
Change "innerHTML" to "chicken" and it appears to work. That is, it only
tests whether there is a writeable property, not whether assigning to it
changes the document structure.
It would succeede in Netscape 4, if the getElementById had worked.


<sigh> CRAP! </sigh>

I knew I was missing something.........
--
Randy
Jul 20 '05 #55
JRS: In article <20***************************@mb-m27.aol.com>, seen in
news:comp.lang.javascript, HikksNotAtHome <hi************@aol.com>
posted at Sat, 3 Jan 2004 18:59:07 :-
Just for my own curiosity, do you see any problems with the function I wrote to
check to see if it works?

function insertHTML(elem,newHTML){
tempVar = document.getElementById(elem).innerHTML;
document.getElementById(elem).innerHTML = newHTML;
if (tempVar == document.getElementById(elem).innerHTML) {alert('It failed')}
}


One needs also to check that it fails correctly!

Consider
insertHTML('F', 'OK')
insertHTML('F', 'OK')
The second one will report failure. A script could well have an error-
message Div, writing 'OK' or a fault-report to it for each iteration.

I get no alert on once executing a version of the above with innerHTML
changed to innnerHTML, which implies that the pre-existence of innerHTML
must be tested.

One might read the existing innerHTML, add a character to it, write it,
and read back; that seems OK even if innerHTML is undefined.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #56

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

Similar topics

3
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
7
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
3
by: Craig | last post by:
Hi, What I'm trying (quite poorly) to do is make it so when a link is clicked the text inside a div or p changes. I've tried numerous things, most of which work in IE but none of which work in...
8
by: Daniel Hansen | last post by:
I know this must seem totally basic and stupid, but I cannot find any reference that describes how to control the spacing between <p>...</p> and <div>...</div> blocks. When I implement these on a...
6
by: Marcus Otmarsen | last post by:
Ok, the situation is as follows: I defined a <DIV> like: <div id="myid" style="position: absolute; height: 10; width: 10;"><img src="images/object.gif" height=10 width=10></div> This pane is...
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
2
by: paul | last post by:
I have a JS function to change the width of a <divthat works great in Firefox, but not at all in IE7. In IE an error message occurs: Line: 92 Char: 5 Error: Invalid Argument Code: 0 Firefox...
2
by: haroon426 | last post by:
Can anyone plz tell me that how to change the font color of the text in the <div> in server side programming Page_Load() event.
8
by: richard | last post by:
I have <div id=box1 style="display:block"as the initial setting. I need to change the "display:block" to "display:none" then back to "display:block" as a means of clearing anything that might be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
0
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
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...
0
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,...
0
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...

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.