DOM2 Reference

Document.getElementById

Text in the first DIV.
Some text in the second DIV.
Some text and element in the third DIV.
We can try another elements. It will be much more interesting.
Text in the last DIV.
Source:
       <div id="doc">
         <div>
           Text in the first DIV.
         </div>
         <div id="DDD" class="secondClass">
           Some text in the second DIV.
         </div>
         <div class="thirdClass">
           Some text and <span id="SSS">element</span> in the third DIV.
         </div>
         <div class="fourthClass">
           We can try <i>another elements</i>.
           It will be much more <b>interesting</b>.
         </div>
         <div>
           Text in the last DIV.
         </div>
       </div>
     
JavaScript:
  var output1 = document.getElementById('doc').nodeName;
  var output2 = document.getElementById('SSS').nodeName;
Output:
desired your browser
output1: DIV
output2: SPAN


Remarks:
  • it seems that all relevant browsers support JavaScript try-catch statement therefore all examples are encapsulated with it (it avoids alert-popups)
  • thanks to White Space Handling in XML 1.0 specification default handling of white-spaces completely depends on XML application (note: WinIE do not preserve white-spaces by default while MacIE and Mozilla does)
  • during development tested with Mozilla night-builds, Netscape6, MicrosoftInternetExplorer5.5 and Opera5.02 on Windows2000



_____________________________________________
Reference Search | Sitemap | XML Glossary       ZVON | IDOOX