/
How do we make a Javascript sandbox

How do we make a Javascript sandbox

You can make a Javascript sandbox by creating an index.html file in a directory with another file with a .js extension with a text editor. Here’s the HTML content:

<html> <head> <script src="DEBUGhelpers.js"></script> </head> <body> <h1>Hello World of Javascript</h1> <p>Here is some text.</p> <div>And a div!</div> <ul> <li>A list item.</li> <li>Another list item.</li> </ul> </body> </html>

Here’s a little Javascript function which will put red outlines around your HTML elements. BTW it’s best practice to separate Javascript and HTML like this.

function DEBUGborders(){ console.log("Borders on"); var Element = document.createElement('style'); document.head.appendChild(Element); var Sheet = Element.sheet; Sheet.insertRule("*{outline: 1px red solid;}", 0); }

Open the index.html page in your browser and type in “DEBUGborders()” at the console and you should see something like this:

 

Related content

JSON - JavaScript Object Notation
JSON - JavaScript Object Notation
Read with this
Sandbox in javascript developer tools
Sandbox in javascript developer tools
More like this
Using Prefixed Name Spaces with Javascript
Using Prefixed Name Spaces with Javascript
Read with this
How can we make a CSS debug tool
How can we make a CSS debug tool
More like this
How do we have a Javascript callback when the page is loaded?
How do we have a Javascript callback when the page is loaded?
Read with this
CSS Borders - Useful for debugging
CSS Borders - Useful for debugging
More like this