Approximately 2.5 hours
- 6 minutes for video walkthrough of slides
- 90 minutes for Independent Practice
- 30 minutes for challenge
- 10 minutes for Check for Understanding
jQuery is a popular and easy-to-learn JavaScript library that allows you to manipulate HTML elements. jQuery allows developers to quickly make webpages interactive across different browsers.
A lot of prominent tech companies use jQuery as part of their frontend stack, including GitHub and Stack Overflow. You can use wappalyzer.com to discover more companies that use it.
Participants will be able to:
- Link to jQuery in their HTML pages in the correct place
- Incorporate jQuery code in the correct place in their HTML files
- Select HTML elements by their element type, class and ID with jQuery
- Implement the
.on("click")
and.on("hover")
jQuery methods - Implement the
.append()
jQuery method - Implement the
.remove()
and.empty()
jQuery methods
- How to incorporate jQuery into a webpage
- How to select HTML elements
- Common and useful jQuery methods for basic interactivity
- Dynamically add or remove HTML elements
- jQuery is not the same as JavaScript. jQuery is a library written in JavaScript that allows developers to write simpler JavaScript and makes JavaScript behave consistently in different browsers.
- Remember to use
.
to select classes and#
to select ids. - There are several jQuery methods that achieve similar goals but through different means. You should understand how they're different so you can use them appropriately.
.remove()
vs.empty()
.text()
vs.val()
vs.html()
Work through the jQuery tutorial on Treehouse.
For each of the following links, read the code and play around with its functionality. You can refresh the webpage to reset it.
Here is some code and a sandbox for .on("click")
.
Here is some code and a sandbox for .hover()
.
Here is some code and a sandbox for .append()
.
Here is some code and a sandbox for .remove()
.
Here is some code and a sandbox for .empty()
.
-
Using your Terminal, create a new directory inside your assignments directory and give it the name
jquery-play
. -
Navigate to
jquery-play
. Open the whole directory in VS Code using the Terminal shortcut you learned in the "Local Development with VS Code" lesson. -
Create a file called
index.html
. It should automatically appear in the left sidebar in VS Code as an editable file. -
Read this example code and talk through it with your pair partner. Once you understand what it does, copy it into
index.html
and save the file. -
Open
index.html
in a new Chrome tab. What do you see? Is this what you expected, based on the code you read? -
Create a new directory called
static
. Navigate tostatic
. Remember that all CSS and JS files go in thisstatic
folder. -
Create a new directory called
js
. Navigate tojs
. -
Create a file in the
js
directory calledmyScript.js
. It should automatically appear in the left sidebar in VS Code as an editable file. -
Read this example code and talk through it with your pair partner. Once you understand what it does, copy it into
myScript.js
and save the file. -
Refresh the Chrome tab that is currently rendering
index.html
. What happens? What do you see? What are you now able to do?
-
Using the jQuery documentation or other resources as your guide, add the ability to change a paragraph's font size when it is clicked.
-
Using the jQuery documentation or other resources as your guide, add the ability to change an element's color when you hover over it with your mouse.
- jQuery official Documentation
- Code School's jQuery course
- jQuery tutorial on codecademy.
- Get more practice by working through this jQuery tutorial on Code School.
- Where in an HTML document do you link to the jQuery CDN?
- Where in the HTML document do you write your jQuery code?
- Where in the HTML document would you link to an external JavaScript file if you were using one?
- What are the 3 ways we can select HTML elements for manipulation using jQuery?
- Name at least 4 jQuery methods you used or saw today.
- Where would you look to find more jQuery methods?