Re-Introduction to HTML

I am refamilarizing myself with html. I started with the What is the DOM example at :

in the section: Testing the DOM API. -----> CODE COPIED BELOW

I copied this text into a document. Saved it as html. Verified the file is a HTML by checking the properties on the file.

When open in Mozilla browser, it shows the code instead of the rendering of the text and buttons as expected. Javascript is enabled on my browser

What do I need to do to get the html to “run”?

    <title>DOM Tests</title>
    <script type="application/javascript">
    function setBodyAttr(attr, value){
      if (document.body) eval('document.body.'+attr+'="'+value+'"');
      else notSupported();
    <div style="margin: .5in; height: 400;"> 
        <select onChange="setBodyAttr('text',
          <option value="black">black 
          <option value="darkblue">darkblue 
        <select onChange="setBodyAttr('bgColor',
          <option value="white">white 
          <option value="lightgrey">gray
        <select onChange="setBodyAttr('link',
          <option value="blue">blue
          <option value="green">green
        </select>  <small>
        <a href="" id="sample">
        (sample link)</a></small><br>
        <input type="button" value="version" onclick="ver()" />

Please share code? There are multiple code samples on the linked page

Right click on the file, and select: properties, verify its indeed a html file. (if you need help, upload a screenshot of the properties of the file)

Done … code executed. Will need to look at sources if possible.

so its working now? :slight_smile:

what do you mean?

Code works when embedded in another html file. How can I get the code to work stand-alone?

define embedded? If done right, it should work as stand-alone file. These problems are so difficult to troubleshoot over a forum. Create a new html file, ensure you select all file types when saving the file, so you give the file its type by extension in the name

Good news - works!. Used Notebook over the editor which showed ‘html’ as a selectable file type.

or simple select all types if html is not enviable as selectable file type, and provide the file type through the extension. If you leave it to .txt for example, it will be a txt file regardless of the extension you give it (for windows that is)

Using the document.getElementById(id) with the following code snippet what is error thrown is expected?

    var parentDOM = document.getElementById('parent-id');
    var test1=parentDOM.getElementById('test1');
    //throw error
    //Uncaught TypeError: parentDOM.getElementById is not a function


i don’t know how and where parentDOM is defined. This should be a separate topic given its a different question

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.