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>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
<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.Even t.onDOMReady(fu nction()
{
var textdiv = document.getEle mentById("textd iv");
var textcontent =
YAHOO.util.Dom. getFirstChild(t extdiv);
alert(textconte nt);
});
</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>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
>
<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.Even t.onDOMReady(fu nction()
{
var textdiv = document.getEle mentById("textd iv");
var textcontent =
YAHOO.util.Dom. getFirstChild(t extdiv);
alert(textconte nt);
});
</script>
</body>
</html>
Comment