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 trialS.M.Mohieminul Hossain
3,329 PointsDifference between Printing functions
What is the difference between console.log and document.write functions
3 Answers
Ben Singer
8,621 Pointsconsole.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.
Ben Singer
8,621 PointsNo problem!
byteknacker
Courses Plus Student 2,984 PointsHow can you direct the printing of document.write function to the specific location within a website?
Juliana Demarque
14,502 PointsI 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.
S.M.Mohieminul Hossain
3,329 PointsS.M.Mohieminul Hossain
3,329 PointsThank you Ben