How to use JavaScript

In this article I am going to explain about how to work with JavaScript.
  • 2084

JavaScript How to use

JavaScript is the scripting language. It is must popular language in the world that use for add interactivity in Html page. It was develop for Netscape Navigator Browser but in this time its run in all major browser such as Internet Explorer, Firefox, Chrome, Opera and Safari.

  • JavaScript can be use in HTML, CSS, DOM (Document object model).
  • For use JavaScript in my document we use <script> tag.
  • JavaScript can be use in Head and body Section in my document.
  • For Access Html element from JavaScript we use document.GetelementById() methocd.
  • "Id" attribute use to identify Html element.
  • For creating function in JavaScript we use "Function" keyword.
  • If any browser does not JavaScript then its display JavaScript as page content.

How to insert JavaScript in my Html document.

<html>

<head>

    <script type="text/jscript">

                  //your JavaScript Statement

    </script>

</head>

<body>

    <h1>

        My first JavaScript program</h1>

</body>

</html>

 

How to create a JavaScript function and how to call it.

 

<html>

<head>

    <script type="text/jscript">

               function Myfunction() {

            document.write("<h4>My first JavaScript program</h4>");

        }

    </script>

</head>

<body>

    <button onclick="Myfunction()">

        click me</button>

</body>

</html>

 

How to call function by function.

 

<html>

<head>

    <script type="text/jscript">

               function Myfunction(name, Address) {

            document.write("Name=" + name, "    Address=" + Address);

        }

        function Display() {

            var str = Myfunction("Shayam", "Delhi");

        }

    </script>

</head>

<body>

    <button onclick="Display()">

        click me</button>

</body>

</html>

 

Output

 

howto.jpg


Further Readings

You may also want to read these related articles: here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.