Use a JavaScript library such as jQuery

Let's place and use a JavaScript library such as jQuery.

Websites created with Giblog can use JavaScript in static CMS.

Here, let's use jQuery as an example.

The method is to download jQuery, place it, and use it.

jQuery official website-download

Pay attention to the following part at the top of the site.

Download the compressed, production jQuery 3.4.1

The May 8, 2019 version is 3.4.1.

Right-click on this link and save it as a name.

The name should be something like "jquery-3.4.1.min.js".

JavaScript allows you to use dynamic expressions on your site.

Place the JavaScript library

First, you need to deploy the JavaScript library.

Let's assume that the saved name is "jquery-3.4.1.min.js" and place it in the following directory.

templates / static / js

Load the JavaScript library

Next you need to load the JavaScript library. The JavaScript library needs to be loaded before it can be used.

It is recommended to load it in the head section of HTML. Write it in the following file.

templates / common / meta.html

Open the file and write the following line.

<script src = "/ js / jquery-3.4.1.min.js"> </script>

JavaScript can be read with a script tag, and the path is described in the src attribute.

"Hello" with jQuery

Next, let's actually use jQuery.

Try opening your favorite content, such as blog posts or index.html.

At the top of this, write:

  $(function () {
    alert ('Hello');

It's written in jQuery syntax.

When you open the page where this JavaScript is written, the message box "Hello" is displayed.