[HTML5] script tag --Write and execute JavaScript

You can write and execute JavaScript using the script tag .

<script src = "https://code.jquery.com/jquery-3.4.1.min.js"> </script>
<script>
  
  $(function () {
    $('.js-hello'). on ('click', function () {
      alert ('Hello');
    });
  });
</script>

<div>
  <button class = "js-hello"> Run script </button>
</div>

Using JavaScript and jQuery, "Hello" is displayed when the button is pressed.

Load an external JavaScript file

You can use the src attribute of the script tag to load an external JavaScript file.

<script src = "/ js / myapi.js"> </script>
<script src = "https://code.jquery.com/jquery-3.4.1.min.js"> </script>

Either a local file or a file on the Internet is fine.

Associated Information