www.webdeveloper.com
Results 1 to 11 of 11

Thread: Append New Line to text in <p> element

Threaded View

  1. #1
    Join Date
    Nov 2006
    Location
    Oceanside, CA
    Posts
    11

    Append New Line to text in <p> element

    I am trying to make sense of the uses of the document.all and/or document.getElementbyId javascript functions. I just thought that I could use this code:
    Code:
    <script type="text/javascript">
    function AppendNewLine()
    {
    document.write("In Function");
    var myPar = document.getElementbyId("myP");
    myPar+="\n";
    myPar+="New Line?\n";
    document.write(MyPar);
    }
    </script>
    <p id="myP" value="value" >Append New Line<br /></p>
    <input type="button" value="Append" onclick="AppendNewLine()" />
    to append a new line to a paragraph on the page. Can someone tell me if I am on the right track, and where I went wrong, or am I all together wrong and where should I restart, and especially, WHY this doesn't work?

    From this link:
    http://www.webdeveloper.com/forum/ar...p/t-93903.html

    I see a way to append to the whole document, but not to an individual <p> element.

    I had already begun to change my code, when I realized that it wasn't going to be applied to the p element:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function AppendNewLine()
    {
    document.write("In Function");
    myText = document.createTextNode('\nNew Line?');
    myParagraph.appendChild(myText);
    
    var myPar = document.getElementbyId("myP");
    myPar+="\n";
    myPar+="";
    document.write(MyPar);
    }
    </script>
    </head>
    <body>
    <p id="myP" value="value" >Append New Line<br /></p>
    <input type="button" value="Append" onclick="AppendNewLine()" />
    </body>
    Last edited by edcompsci; 07-22-2010 at 06:50 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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