www.webdeveloper.com
Results 1 to 2 of 2

Thread: Display Text to Page

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    74

    Display Text to Page

    .innerHTML is used when you trigger an event but if you just want to display the text how would you go about do it??
    I don't want to used document.writeln because it will "Wipe out all the contents" of that page.
    So I have some HTML text and javascript text. I would like both to display on my page.

    Here's my code

    Code:
    <html>
    <head>
    
    <script type="text/javascript"> 
    function display() {
       document.writeln("How do I make both text appear");
    }
    </script>
    </head>
    
    <body onload="display()">
    I would like this text in the body to remain.
    
    <script type="text/javascript">
       display();
    </script>
    
    
    </body>
    </html>
    thanks
    *** link removed by moderator - please do not spam this site ***

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,350

    Lightbulb

    Some of your statements are wrong, but are not critical to your problem.

    .innerHTML can be used for things other than events
    and
    document.write can be used before the page is displayed
    so long as you don't use it again later after the page has loaded.

    Code:
    <html>
    <head>
    
    <script type="text/javascript"> 
    function display() {
       document.getElementById('addedText').innerHTML
         = "How do I make both text appear"
         + ":<br>Like this as the 2nd sentence";
    }
    window.onload = function() {
      display();
    }
    </script>
    </head>
    
    <body onload="display()">
    I would like this text in the body to remain.
    
    <div id="addedText"></div>
    
    <script type="text/javascript">
      document.write('I would like this to appear as the 3rd sentence');
    </script>
    </body>
    </html>
    Code is untested at this time, but should be close to your needs.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles