Jump to content


JS equivalent of "Echo"??

  • Please log in to reply
3 replies to this topic

#1 Heyitsrick


    New member

  • New Members
  • 9 posts

Posted 23 April 2012 - 08:15 AM

Yes, the newbiest of questions, 'tis true, but what is the JS equivalent of PHP's "Echo" command? I know about using the Alert box, but that's not what I want. I just want a simple "Hello World" on the page, not as a pop up.

Now, I also know about document.write, too..BUT w3schools' page on this specifically says not to use it in "live" code because it could/would rewrite an entire page after loading.

Here's their blurb:

"Note: Try to avoid using document.write() in real life JavaScript code. The entire HTML page will be overwritten if document.write() is used inside a function, or after the page is loaded. However, document.write() is an easy way to demonstrate JavaScript output in a tutorial."

There has to be something simple that just echoes to the screen in javascript without causing other problems, no?

Note: This isn't one of those questions where I'm looking for people to ask "why do you even want JS to do that as there are better options?". It's just one of those "what's the equivalent" questions for my own knowledge. Thanks.
  • 0

#2 benjaminmorgan


    Advanced Member

  • Member
  • PipPipPipPip
  • 237 posts

Posted 23 April 2012 - 04:34 PM

I guess you could use innerHTML.

<script type="text/javascript">
document.getElementById('inner').innerHTML = "Hello World!";

<p id="inner"></p>

  • 0
Things should be made as simple as possible, but not any simpler. -Albert Einstein

#3 mindgrinder


    New member

  • New Members
  • 9 posts

Posted 25 May 2012 - 11:06 AM

try console.log()
  • 0

#4 Ben



  • Administrators
  • 5,682 posts
  • LocationGainesville, Florida

Posted 25 May 2012 - 02:51 PM

try console.log()

A quick FYI -- console.log() isn't the same thing as "echo", since console.log prints the results off screen, in the Javascript console, while echo displays content within the page.
  • 0
Benjamin Falk
Falken Creative : Twitter

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

★★★★★ 5 Star Rated Web Developer Course - check it out now!