D
david.karr
I have a simple test page with a "div" that just contains text
content. I assigned a var to the "div" element, and I'm trying to get
the "first child" of that element to get the text content. I'm
stepping through the code in firebug, and the var pointing to the div
looks correct, and it even shows the "firstChild" is my text content.
However, when I execute the line to get the first child, the result is
null.
I'm using YUI for this, but I doubt I'm making a YUI-specific mistake.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<title>Text Content Problem</title>
<script type="text/javascript" src="yui/yahoo-dom-event/yahoo-
dom-event.js"></script>
<script type="text/javascript" src="yui/element/element-beta-
min.js"></script>
</head>
<body>
<div id="textdiv">
This is some text.
</div>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function()
{
var textdiv = document.getElementById("textdiv");
var textcontent =
YAHOO.util.Dom.getFirstChild(textdiv);
alert(textcontent);
});
</script>
</body>
</html>
content. I assigned a var to the "div" element, and I'm trying to get
the "first child" of that element to get the text content. I'm
stepping through the code in firebug, and the var pointing to the div
looks correct, and it even shows the "firstChild" is my text content.
However, when I execute the line to get the first child, the result is
null.
I'm using YUI for this, but I doubt I'm making a YUI-specific mistake.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<html>
<title>Text Content Problem</title>
<script type="text/javascript" src="yui/yahoo-dom-event/yahoo-
dom-event.js"></script>
<script type="text/javascript" src="yui/element/element-beta-
min.js"></script>
</head>
<body>
<div id="textdiv">
This is some text.
</div>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function()
{
var textdiv = document.getElementById("textdiv");
var textcontent =
YAHOO.util.Dom.getFirstChild(textdiv);
alert(textcontent);
});
</script>
</body>
</html>