how would I add text that the viewer could see and not just to the console as well as it not getting rid of the other text on the page?

<!DOCTYPE html>
<html>
  <head>
    <title>help me</title>
  </head>
  <body>
   <p>this is a line of text</p>
   <p>this is another line of text</p>

   <script>
    //what would I add here
   </script>
    <p>how would i add text in between these lines or after using jscript? is it even possible?</p>
  </body>
</html>

thank you for helping me in advance

Hi,
Your question is not clear as to where you purpose to add the text and how you are going about it. Though what you wanted is very possible.
So there is the questioin; Are you adding text to the third paragraph? What text are you adding and where?

Something like this:

       <script>
            var aPList = document.getElementsByTagName("p");
            for (var i = 0; i < aPList.length; i++) {
                if (!aPList[i].hasChildNodes)
                    continue;

                var reg = /jscript/ig;  //use regex exp
                var msg = aPList[i].childNodes[0].nodeValue;
                if (reg.test(msg)) {
                    msg = "<em>Initial String was this: </em>" + msg +
                      "<br/><em>Final String is this: </em>" + "<strong>" + msg.replace(/jscript/,"JavaScript") + "</strong>";
                    aPList[i].innerHTML = msg;
                }
            }
       </script>

Using gives this:

Initial String was this: how would i add text in between these lines or after using jscript? is it even possible?
Final String is this: how would i add text in between these lines or after using JavaScript? is it even possible?

You can even decides to check for which lines as your codes runs. Try that on your own with the code I shown above. It is quite simple.

Hopes this help.

This is a very simple problem. document.write("foo fighters"); rewrites the whole page, so what you have to do is document.write(document.getElementsByTagName("body").innerHTML + "foo fighters");
This gets everything in the <body> tag, and adds "foo fighters" to the end of the string, because the string is everything in the <body> tag. You cound also do:
<img src="stuff" /> in place of "foo fighters", since you are adding an HTML tag to the end of a bunch of HTML tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.