Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:42:51+00:00 2026-06-16T19:42:51+00:00

HTML file … <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html> <head> <meta

  • 0

HTML file …

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="src/myJS.js"></script>
</head>
<body onload="myJS.myFunction();">
<p id="p01"></p>
</body>
</html>

External Javascript file (called myJS.js for convenience) …

myJS = {
    myFunction: function()
    {
        //This works
        document.write("Hello world. ");

        //This does not work
        document.getElementById("p01").appendChild(document.createTextNode("Hello world, again"));
    }
};

My best guess is that the node p01 has not been created when myJS is executed, but I thought that onload would do the right thing with it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:42:52+00:00Added an answer on June 16, 2026 at 7:42 pm

    If your external js really contains both lines of code you posted, the problem is that document.write is overwriting the whole HTML (it behaves like that as soon as the DOM is loaded). Then getElementById won’t find any #p01, because it won’t exist anymore.

    If you simply remove the document.write call, your code is supposed to work (see a live example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've an html file with the below markup: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
My HTML file <!DOCTYPE HTML> <html lang=en-US> <head> <meta charset=UTF-8> <title></title> </head> <body> <p>Hello
this is a simple html file: <!DOCTYPE html> <html> <head> <title>Test Uploading Func.</title> <script
I have a HTML file http://mydomain.com/page1.html : <!doctype html> <html> <iframe src=http://mydomain.com/page2.php></iframe> </html> In
In my HTML file, I have: <html><head> <style>html{width: 320px; } body {padding: 0; margin:
My html file: <html> <head><title>RSS Form</title></head> <body> <form method='post' action='write.php'> <img src='logo.png' align='left' />
This is my HTML file <html> <head> <style type=text/css> body { background-image: url(Images/android_background.png); background-repeat:
My HTML file: <html> <head> <script src=//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js /> <script src=script.js type=text/javascript></script> </head> <body> <form
I wrote the following html file <code> <html> <head> <script text =text/javascript> function createCookie(name,value,days)
I made an html file called test.html then I navigated to it as http://site.com/test.html?test1=a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.