rbuser Posted April 23, 2012 Report Share Posted April 23, 2012 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. Quote Link to comment Share on other sites More sharing options...
benjaminmorgan Posted April 23, 2012 Report Share Posted April 23, 2012 I guess you could use innerHTML. Javascript <script type="text/javascript"> document.getElementById('inner').innerHTML = "Hello World!"; </script> HTML <p id="inner"></p> Quote Link to comment Share on other sites More sharing options...
ibautista Posted May 25, 2012 Report Share Posted May 25, 2012 try console.log() Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 25, 2012 Report Share Posted May 25, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.