Possible Duplicate:
Access DIV element from JavaScript
I have a HTML code like :
<div id="headerlist" >
<h3> Enrollment Efficiency</h3>
</div>
I have to access element Enrollment Efficiency
I am trying with :
var headerlist = document.getElementsById('headerlist');
alert("the value of headerlist is "+ headerlist.firstChild);
But its not working.
Just a typo. It is
getElementById()(no pluralsthere).An
idshould be unique throughout the document, hence only one element should be returned by this functions. If there could be more than one element matched, like withgetElementsByName(), there is a plurals.EDIT
As mentioned by @Cerbrus: The
firstChildattribute, just points to first child element, and not to its contents.To remarks here:
The
firstChildin your example is just a whitespace text node. if you want the next non-whitespace node usefirstElementChild(supported in most modern browswers).To display the contents, use something like
innerHTMLortextContent.