JQuery

From Publication Station

What is jQuery?

jQuery is a library for JavaScript, which is a programming language used to make websites interactive. It's like a set of handy tools that makes it easier for developers to work with JavaScript, allowing them to do things like adding animations and making web pages respond to user actions without writing as much code.

Getting started

1. Prepare your HTML file

Open Visual Studio Code and create a new file. Save the file as index.html, inside of a folder that will contain all the files for this website and noting else. In this file, enter the ! symbol and chose the first option that shows up underneath. This should create a default html file, ready to work with.

2. Add a JavaScript page

Open en new file and save it in the same folder as your html file, name it script.js. In de head of your html document, you should add a link to this JS file:

<script src="script.js"></script>

3. Add jQuery

Before you can use jQuery code in your JavaScript file, you need to load the jQuery library file. the easiest way to do that is to copy the following line of code into the head of your document, above the link to your script file.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

4. Test if it works

Enter the code below in your script.js file to check whether everything works correctly:

$(function() {

alert('Hello world!');

});

This should wait for the page to be loaded and then show a message saying Hello world!