Javascript Examples

The example below writes the current date into an existing <p> element:

Example


<html>
<body>

<h1>My First Web Page</h1>

<p id="demo"></p>

<script type="text/javascript">
document.getElementById("demo").innerHTML=Date();
</script>

</body>
</html>



*Just copy the above code paste it in JAVASCRIPT box and click RUN on the top of the page.



Some Browsers do Not Support JavaScript


Browsers that do not support JavaScript, will display JavaScript as page content.


To prevent them from doing this, and as a part of the JavaScript standard, the HTML comment tag should be used to "hide" the JavaScript.


Just add an HTML comment tag <!-- before the first JavaScript statement, and a --> (end of comment) after the last JavaScript statement, like this:


<html>
<body>
<script type="text/javascript">
<!--
document.getElementById("demo").innerHTML=Date();
//-->
</script>
</body>
</html>

0 Post Your questions:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More