Difference between revisions of "JQuery"

From Publication Station
(new)
Tag: visualeditor
 
Tag: visualeditor
 
Line 8: Line 8:


===== 2. Add a JavaScript page =====
===== 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, by typing script, accepting the first autocomplete option and adding href="script.js" inside the opening script tag.
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:
 
<code><script src="script.js"></script></code>


===== 3. Add jQuery =====
===== 3. Add jQuery =====
Line 16: Line 18:


===== 4. Test if it works =====
===== 4. Test if it works =====
Enter the code below to check whether everything works correctly:<syntaxhighlight lang="javascript">
Enter the code below in your script.js file to check whether everything works correctly:<syntaxhighlight lang="javascript">
$(function() {
$(function() {



Latest revision as of 09:49, 16 November 2023

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!