Kentaro
07-22-2003, 02:06 AM
I want to put text from a certain element of an array inside an HTML DIV element with id="currenttext". For some reason, the document.getElementById() call does nothing (I've used document.write() calls to debug to this point). It returns null. There is nothing inside of the DIV element that I'm trying to refer to but I should still be able to add a text node to it!
Here is the file I'm working with:
<HTML>
<HEAD>
<TITLE>Ticker Javascript (DHTML)</TITLE>
<STYLE>
.tickerbox { background: #000000;
width: 400 px;
height: 30 px;
padding: 5px }
.tickertext { font: 10pt "Arial";
color: #FFFFFF }
</STYLE>
<SCRIPT>
// const interval = 1000;
itemList = ["Hello!", "I'm a ticker!", "I can change!"];
current = 0;
function changeItem()
{
// change from itemList[current] to itemList[next]
}
function startTicker()
{
/* start the ticker animation by displaying itemList[0]
and setting timeout (setTimeout) */
txt = document.createTextNode(itemList[0]);
document.getElementById("currenttext").appendChild(txt);
}
startTicker();
</SCRIPT>
</HEAD>
<BODY>
<P align=center>The following demonstrates a DOM ticker in Internet
Explorer:</P>
<DIV id="ticker" align="center">
<DIV id="mainticker" class="tickerbox" align="center">
<DIV id="currenttext" class="tickertext"></DIV>
</DIV>
</DIV>
</BODY>
</HTML>
Please help! Everytime I've tried to do something remotely fun with the DOM I've gotten nothing but frustration out of it! I've been reading specifications and tutorials for hours on end (for DOM, HTML, CSS, and Javascript). :(
Here is the file I'm working with:
<HTML>
<HEAD>
<TITLE>Ticker Javascript (DHTML)</TITLE>
<STYLE>
.tickerbox { background: #000000;
width: 400 px;
height: 30 px;
padding: 5px }
.tickertext { font: 10pt "Arial";
color: #FFFFFF }
</STYLE>
<SCRIPT>
// const interval = 1000;
itemList = ["Hello!", "I'm a ticker!", "I can change!"];
current = 0;
function changeItem()
{
// change from itemList[current] to itemList[next]
}
function startTicker()
{
/* start the ticker animation by displaying itemList[0]
and setting timeout (setTimeout) */
txt = document.createTextNode(itemList[0]);
document.getElementById("currenttext").appendChild(txt);
}
startTicker();
</SCRIPT>
</HEAD>
<BODY>
<P align=center>The following demonstrates a DOM ticker in Internet
Explorer:</P>
<DIV id="ticker" align="center">
<DIV id="mainticker" class="tickerbox" align="center">
<DIV id="currenttext" class="tickertext"></DIV>
</DIV>
</DIV>
</BODY>
</HTML>
Please help! Everytime I've tried to do something remotely fun with the DOM I've gotten nothing but frustration out of it! I've been reading specifications and tutorials for hours on end (for DOM, HTML, CSS, and Javascript). :(