Welcome to the Treehouse Community
Looking to learn something new?
I've read a lot lately saying the use of document.write (DW) is now bad form. Is this true & what's the alternative??
Most of what I've read & heard lately, including on sites like StackOverflow & the MDN, is that the use of the document.write method for printing output in a page is now frowned upon & its use it is best left for testing & debugging code. From what I understand, using document.write after an HTML document is fully loaded, will delete all existing HTML, which definitely sounds problematic..... Does anyone have an opinion on this &/or any suggestions as to the best alternative method??
document.write is really only useful in a test script, where nothing else is going to be output to the page as it does overwrite all previous content, as you mentioned. When doing debugging, I would use
console.log if you're using Firefox or Chrome or just an
alert if you're using another browser that doesn't have a web console.
textContent method for inserting text into an element than it is to use
innerHTML. You should only use
innerHTML if you're inserting other HTML elements into another element. Here is a JS performance test showing how much faster textContent is versus innerHTML.
As Dmitriy mentioned, if you're using jQuery in your projects familiarize yourself with the
append() methods in jQuery. You can see live examples of them at the api.jquery.com website here.
If you ever have any questions, I or one of the many other helpful students and staff members here at Team Treehouse will help you! =]
Dmitriy Birioukov684 Points