2 Replies - 416 Views - Last Post: 31 August 2013 - 12:01 PM

#1 NoGf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-November 12

Problem with document.write

Posted 31 August 2013 - 11:43 AM

Hello
I'm trying to see what document.write does
Here's my piece of code
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="cssfile.css">
<title>My Page</title>

</head
<body>
<script>
document.write("<p>abc</p>");
</script>
<p id="first">first</p>
<a href="second.html">second</a>

</body>

</html>


However, when I see the results it doesn't show the text.
What seems to be the problem?

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with document.write

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3807
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Re: Problem with document.write

Posted 31 August 2013 - 11:57 AM

You haven't closed your head-tag properly. (Even so, it still writes 'abc' for me.)

However, document.write() should rarely be used in modern code. If content needs to be modified, or inserted, after the page is loaded then a script can be added to the bottom of the page, before the closing body-tag.

I don't know what tutorial you are following, but if it mentions document.write() a lot then I would find a more up-to-date tutorial. We have tutorials here @DIC - click the link at the top of this page.

This post has been edited by andrewsw: 31 August 2013 - 12:01 PM

Was This Post Helpful? 4
  • +
  • -

#3 NoGf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-November 12

Re: Problem with document.write

Posted 31 August 2013 - 12:01 PM

Thanks Andrew.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1