dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: format text generated by javascript

  1. #1
    Join Date
    Nov 2013
    Posts
    2

    format text generated by javascript

    Hi,
    I fount the following code to generate random sentences. It work great and I injected the code into my page. However I would like to be able to format the text generated by the script without affecting the format of the remaining parts of my page. Probably this is very easy to do but I am very new at this and was not able to find the way to format only this specific block.
    Many thanks in advance for any help.

    <html>
    <head>
    <title>Random Text</title>
    <script type="text/javascript">
    var textarray = [
    "sentence 1",
    "sentence 2",
    "sentence 3",
    "sentence 4" // No comma after last entry
    ];

    function RndText() {
    var rannum= Math.floor(Math.random()*textarray.length);
    document.getElementById('ShowText').innerHTML=textarray[rannum];
    }
    onload = function() { RndText(); }

    var inter = setInterval(function() { RndText(); }, 2000);

    </script>
    </head>
    <body>
    <div id="ShowText"></div>
    </body>

    </html>

  2. #2
    Join Date
    Mar 2011
    Posts
    1,160
    It's not clear to me what you have in mind when you say "format". Why not just use CSS to set the styles for your "ShowText" <div>?

  3. #3
    Join Date
    Nov 2013
    Posts
    2
    Doing what you suggested worked, many thanks!

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