Week 10:

Dynamic Documents



JavaScript is able to write directly to the HTML when the page loads.


document.write("This was written to the screen with an inline javascript block.");


$(document).ready(function(){
    $('#modifiedonload').html("This was written to the screen when the document
                            finished loading inside of an existing HTML element.");
});

If the number is less than or equal to 3, this div will be red. If the number is greater than 3, it will be green. The number is

var n = Math.random()*6;    // gets a random floating point number between 0 and 6.
n = Math.floor(n) + 1;      // rounds the number down then adds 1.

if(n <= 3){
    $("#randomdiv").css("background-color", "red");
} else {
    $("#randomdiv").css("background-color", "#090");
}
$("#randomdiv").append(n +".");

Resources