Member-only story

Getting Started with jQuery

John Au-Yeung
3 min readDec 30, 2020

--

Photo by Jukan Tateisi on Unsplash

jQuery is a popular JavaScript for creating dynamic web pages.

In this article, we’ll look at how to using jQuery in our web apps.

Adding jQuery

We can add jQuery by adding a script tag:

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

We can also install the jquery package by running:

npm install jquery

with NPM or:

yarn add jquery

Also, we can install it with Bower:

bower install jquery

After installing it, we can start using it.

.add()

The .add() method lets us get a child element from a parent.

For example, if we have:

<p>
<div>
foo
</div>
</p>

Then we call:

$("p").add("div").addClass("widget");

to get the div that’s inside the p element.

Then we call addClass to add a class to the div inside the p element.

.addBack()

The .addBack() method lets us get the child elements from the parent element.

--

--

No responses yet