Illustrates a JavaScript script block, alert box, and control of the display style of a text block.
Block 1 - Brown before the alert box; green after
This paragraph is placed in the HTML file before the JavaScript script.
Because of a style rule in the embedded style sheet, it is brown when first displayed.
The JavaScript script then uses the statement document.getElementById("block1").style.color="green"; to change its color to green.
alert("This is a JavaScript alert box.\n\nBlocks 1, 3, and 4 are visible. Block 2 is hidden (though the brown line on the page is a border around it), Block 4 was written by inline JavaScript code, and Block 5, which follows the embedded JavaScript block, hasn't been rendered yet.");
document.getElementById("block2").style.display="block"; // Display block 2
document.getElementById("block1").style.color="green"; // Change block 1 to green
Block 5 - visible only after the alert box
This HTML code appears in the HTML file below the inline JavaScript script, so it is not rendered until after the script executes.