#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21

    How to write text in document?


    Hi guys,

    I am working on my javascript to create the text in the html document. I want to know how I can write the text in html?

    I tried to use this:

    Code:
    var test=myFunction();
    
    function myFunction(test)
    {
      var keycode;
      if (window.event) keycode = window.event.keyCode;
      {
        document.write("hello! this is a test");
      }
    }


    It did not write the text in the html. I tried to find the solution but i can't.

    Can you please help me?

    thanks in advance.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,118
    Rep Power
    119
    Do some online searching for: innerHTML, appendChild, & createTextNode. These are all ways you can add text to a document, from within a function.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    Thanks for your help. I will take a look into this and I will get back to you if I have any problem.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    hey web_loone08. I have got a problem right here, the text did not appear on my webpage after I wrote this in my javascript:

    Code:
    text1.style.visibility = "visible";

    Here is the span tag I have input in the html page:

    Code:
    <span id="text1"><span style="font-family:Arial;font-size:13px;font-style:normal;font-weight:normal;text-decoration:none;text-transform:none; position:absolute; visibility:hidden; overflow:hidden; left:50px; top:40px; width:376px; height:90px; z-index:0">this is a text </span></span>

    Do you have any idea how to display them in my webpage?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    Your visibility inline style is part of the inner span element, try moving it out to the span with the ID:

    Code:
    <span id="text1" style="visibility:hidden;"><span style="font-family:Arial;font-size:13px;font-style:normal;font-weight:normal;text-decoration:none;text-transform:none; position:absolute; overflow:hidden; left:50px; top:40px; width:376px; height:90px; z-index:0">this is a text </span></span>
    Code:
    text1.style.visibility = "visible";

IMN logo majestic logo threadwatch logo seochat tools logo