Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.