show-notice
hide-notice

Wednesday, 24 July 2013

How to code Block in JavaScript


Introduction

JavaScript statements can be grouped together in blocks.Blocks start with a left curly bracket, and end with a right curly bracket.The purpose of a block is to make the sequence of statements execute together.A good example of statements grouped together in blocks, are JavaScript functions.
Example
<html>
<body>

<h1>My Web Page</h1>

<p id="myPar">I am a paragraph.</p>
<div id="myDiv">I am a div.</div>

<p>
<button type="button" onclick="myFunction()">Try it</button>
</p>

<script>
function myFunction()
{
document.getElementById("myPar").innerHTML="Hello Dolly";
document.getElementById("myDiv").innerHTML="How are you?";
}
</script>

<p>When you click on "Try it", the two elements will change.</p>

</body>
</html>



SHARE THIS POST   

0 comments :

Post a Comment

Design by Gohilinfotech | www.gohilinfotech.blogspot.com