Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Introducing JavaScript The JavaScript Console

Difference between Printing functions

What is the difference between console.log and document.write functions

3 Answers

console.log only prints to the javascript console in the browser's developer tools.

document.write will print the contents of a function's output to the body of the webpage, itself.

Thank you Ben

No problem!

How can you direct the printing of document.write function to the specific location within a website?

Juliana Demarque
Juliana Demarque
14,502 Points

I believe it would be best to query the DOM element you want and use the innerHTML property to write the content you want inside of it. Like so, for example:

document.getElementById("my-element").innerHTML = "My content";

Note that in the example above, you should have created that element already, with or without JavaScript.