Results 1 to 2 of 2

Thread: Help me with Javascript

  1. #1
    Join Date
    Nov 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me with Javascript

    Iím learning Javascript these days,using The book called Dom programming art
    Here is the problem,I want to use JS to create content,but nothing happen when I open my html document. Whatís the problem? Thank you
    Here is the code below:

    Code:
    window.onload=function(){
    	var para=document.creatElement("p");
    	var txt=document.creatTextNode("hello world");
    	para.appendChild(txt);
    	var testdiv=document.getElementById("testdiv");
    	testdiv.appendChild(para);
    HTML Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8"/>
      <title>Test</title>
     </head>
     <body>
     <div id="testdiv">
     </div>
      <script type="text/javascript" src="scripts/example.js"></script>
     </body>
     </html>
    }

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Hello akiloama,
    The curly brace you've put at the end of the HTML must be put at the end of the javascript. And 'creat' must be replaced with 'create' everywhere. So your code should look like this:
    Javascript:
    Code:
    window.onload=function(){
    	var para=document.createElement("p");
    	var txt=document.createTextNode("hello world");
    	para.appendChild(txt);
    	var testdiv=document.getElementById("testdiv");
    	testdiv.appendChild(para);
    }
    HTML:
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8"/>
      <title>Test</title>
     </head>
     <body>
     <div id="testdiv">
     </div>
      <script type="text/javascript" src="scripts/example.js"></script>
     </body>
     </html>

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2008, 02:38 PM
  2. Javascript.AJAX link inside javascript dropdownmenu
    By Possemaster in forum JavaScript
    Replies: 2
    Last Post: 01-25-2008, 09:46 AM
  3. 3rd javascript not supporting in side the javascript program
    By raju in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-24-2007, 10:34 AM
  4. [Ajax XML Ticker ] javascript execute in javascript
    By Borsti26 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 02-21-2007, 04:33 PM
  5. [Javascript] Class-Based Javascript Analog Clock
    By ByteMyCode in forum Submit a DHTML or CSS code
    Replies: 2
    Last Post: 10-14-2006, 10:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •