Make delicious recipes!

Scripts



HTML by itself is pretty much static.
Javascript brings dynamic content to HTML and also provides a way to manipulate the HTML programmatically.

Scripts can be included in HTML by making use of the <script> tag.
This has 2 flavors:
  1. In-place script:
    <script>
        alert("Hello World");
    </script>
    
  2. Reading script from file:
    <script src="url-for-js-file">
    </script>
    




Example: A dynamic table can be built in Javascript as follows:



<div id="demoDiv">
</div>

<script>

    var demoDiv = document.getElementById("demoDiv");
    var tbl = document.createElement ("TABLE");
    tbl.border=1;

    demoDiv.appendChild (tbl);

    for (var i=0; i<3; i++)
    {
        var row = tbl.insertRow(-1);
        for (var j=0; j<5; j++)
        {
            var cell = row.insertCell(-1);
            cell.innerHTML = i+","+j;
        }
    }		
</script>




For further reading, please see the Javascript article.





Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal