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

Karina Rogers
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Karina Rogers
Front End Web Development Techdegree Graduate 15,909 Points

Is document.write() outdated? When running this code, I get the following 'violation' message...

Here is my code:

alert("Hello, thanks for visiting");
console.log("Hello from the console");
document.write("<h1>Welcome to my page</h1>");

When I run it in the console, I get the following message: [Violation] Avoid using document.write(). https://developers.google.com/web/updates/2016/08/removing-document-write

Am I doing something wrong or is document.write() outdated?

1 Answer

Hmm....I copy/pasted the exact code to my Workspace, and it displayed the message without any errors. So, I'm not sure.

Edit: I copy/pasted the exact code directly to the console too, still no errors except when I paste the code to the console on a blank tab. Then I get This document requires 'TrustedHTML' assignment error.