newbie: createTextNode & Div

J

Jeff

Hey


This SwapText method fails to add a text node to the "info" Div element.
<head>
<script type="text/javascript" language="JavaScript">
function SwapText(text)
{
var mycel = document.getElementById("info");
var newtxt = mycel.createTextNode(text);
mycel.appendChild(newtxt);
}
</script>
</head>
<body>
<div id="gui">
<div id="content">
<div id="region">
<table width="100%" border="2" cellspacing="0"
cellpadding="0" align="center">
<tr>
<td width='200'>
<a href='test.php' onmouseover='SwapText("Hello
world 2.0 beta")' onmouseout='SwapText()'>
<img src=test.png />
</a>
</td>
</tr>
</table>
</div>
<div id="info">
</div>
</div>
</div>
</body>

The javascript function fails to add a new text node to the "info" div.

(( I'm using Microsoft IE 6.0.2900 - latest version & winXP pro sp2 ))

What am I doing wrong here?

Please help me

Jeff
 
W

web.dev

Jeff said:
Hey


This SwapText method fails to add a text node to the "info" Div element.
<head>
<script type="text/javascript" language="JavaScript">
function SwapText(text)
{
var mycel = document.getElementById("info");
var newtxt = mycel.createTextNode(text);
mycel.appendChild(newtxt);
}
</script>
[snip]

It should be instead:

var newtxt = document.createTextNode(text);

And also judging by the name of your function, it will not "swap" the
text, rather it will keep appending more and more text.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top