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

  • Home
  • SEARCH
  • 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 8018935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:14:44+00:00 2026-06-04T21:14:44+00:00

I am messing around with JavaScript experimenting to get a feel for it and

  • 0

I am messing around with JavaScript experimenting to get a feel for it and have already hit a problem. Here is my html code:

<!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=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<script type="text/javascript" src="testing.js"></script>
</head>
<body onload="writeLine()">
</body>
</html>

Here is the JavaScript testing.js:

function writeLine()
{
    document.write("Hello World!")
}

Here is the style sheet styles.css:

html, body {
    background-color: red;
}

So a very simple example, but I may have chose an awkward example, using on-load in a body tag. So the code above loads and runs the function, but the style sheet does nothing, unless I remove the script tags in the head. I have tried putting the script tags everywhere else, but nothing works. I have researched on-line how to properly link to JavaScript files, and have no found no clear solution, can anyone point out my error?

I have used JavaScript before, but I want a clear understanding from the beginning before I use it any longer

  • 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-04T21:14:45+00:00Added an answer on June 4, 2026 at 9:14 pm

    Your problem is with the document.write() called in a wrong moment*. This method prints given text at current place in the page as was intended to work while the page still loads. Because you are calling it when the whole page was loaded, the results are unexpected (undefined?)

    Instead you should manipulate the dom tree directly:

    function writeLine() {
        var text = document.createTextNode("Hello World!");
        document.body.appendChild(text);
    }
    

    Actually in Opera browser I see red background for few milliseconds and then it goes back to white. Try commenting out document.write() – the background is as expected. Moreover you should include <script> tag at the end of body, but this won’t solve your problem.

    * to be honest, there is no good moment for calling document.write(), avoid it

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

Sidebar

Related Questions

I have been messing around with the Google's JavaScript code and I saw in
I'm studying a few JavaScript books, messing around with Node.js/Express/Jade/Backbone.js and experimenting with a
I'm just messing around learning about JavaScript and I wanted to change the color
Im just messing around with Ruby on Rails and HTML. This question isn't about
I was just messing around to answer someone's question here on Stack Overflow, when
I have finally started messing around with creating some apps that work with RESTful
I'm messing around with some windows functions using p/invoke. Occasionally, I get an error
I was messing around with JavaScript, and noticed that this can never be a
Yeah so I've been messing around with javascript a while but only recently got
I was playing around with some JavaScript code and found that when I took

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.