How To Include JavaScript in HTML page


hello friends I am Shyam and today I will talk with you about how to run JavaScript in your browser.
 So friends JavaScript will be run of three types in your browser -- 

1)- The first type is the inline type where your JavaScript writes on your same page and in the HTML tag. 

2)-Second type - here you can write your JavaScript in an external file and include it in your webpage. 

3)- Third type -
         third type in the internal JavaScript type and here you can write your JavaScript code in Java script tag for example here you can see the example of the first second and third type of JavaScript writing in the web page.


example first -

<button class="btn btn-primary" onclick="alert('Hello Shyam_Sir');"> Click Here</button>



Second Type Example-

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

<script>
function myFunction() {
  var name = prompt("Please enter your name", "Your Name");
  if (person != null) {
    document.getElementById("demo").innerHTML =person;
  }
}
</script>


Third Type - 
                    <script src="myscripts.js"></script>

Here  you need to make a file and in this you can write your javascript without script tag like this -

var a=10;
var b = 20;
alert(a+b);
console.log(a+b);


And this file save with myscripts.js

But in wordpress you can not use like this - in wordpress you meed to include like this -

function  function_name_scripts() {

    wp_enqueue_script( 'script-name', get_template_directory_uri() . 'example.js', array('jquery'), );
}
add_action( 'wp_enqueue_scripts',  'function_name_scripts' );




Note : This all type of include or use type of javascript in your HTML page . If you learn something from here than please comment below.

Er. Shyam Sir