Here’s a list of 60 jQuery exercises, categorized by difficulty and functionality.
Basic jQuery Exercises
- Include a jQuery file in an HTML document and verify functionality with
console.log
. - Change the text of a
<p>
tag on a button click. - Hide and show a
<div>
using jQueryhide()
andshow()
. - Toggle the visibility of an element using
toggle()
. - Add a class to an element on button click using
addClass()
. - Remove a class from an element on button click using
removeClass()
. - Append a
<li>
to a<ul>
dynamically. - Prepend a new
<li>
to a list. - Create a simple fade-in effect on an image.
- Create a fade-out effect on a
<div>
.
Selectors and Events
- Select all
<p>
tags and change their text color to red. - Select the first
<li>
in an ordered list and underline it. - Select the last
<li>
in an unordered list and change its font size. - Add an event listener to a button that logs “Button clicked!”.
- Change the background color of all even rows in a table.
- Toggle the visibility of all
<img>
tags when clicked. - Count the number of
<div>
elements on the page and display the count. - Display the text of a
<span>
when it is clicked. - Highlight the text of an input field when it gains focus.
- Remove the highlight from an input field when it loses focus.
Manipulating DOM Elements
- Insert text before an element using
before()
. - Insert text after an element using
after()
. - Replace the text of a
<h1>
tag dynamically. - Clone a
<div>
and append the copy to the body. - Wrap a
<span>
around all<p>
tags on the page. - Remove an element from the DOM when a button is clicked.
- Detach an element and re-attach it on another button click.
- Append a new row to a table dynamically.
- Add a placeholder text to an input field.
- Create a new element dynamically and add it to the page.
CSS and Animation
- Change the width of a
<div>
to 300px on button click. - Increase the height of a
<div>
over 2 seconds usinganimate()
. - Change the font size of a paragraph using
css()
. - Create a sliding effect using
slideUp()
. - Create a sliding effect using
slideDown()
. - Create a toggle sliding effect using
slideToggle()
. - Animate a circle moving 200px to the right.
- Create a fade effect with
fadeToggle()
. - Change the opacity of an image dynamically.
- Rotate a
<div>
on button click.
Form Handling
- Display the value of an input field when the user presses Enter.
- Clear the value of an input field on button click.
- Validate that an input field is not empty.
- Count the characters entered in a textarea and display the count.
- Enable or disable a button based on a checkbox toggle.
- Populate a dropdown dynamically from a JavaScript array.
- Display the selected value from a dropdown menu.
- Create a dynamic search filter for a list of items.
- Auto-fill an address form based on a dropdown selection.
- Prevent form submission if certain fields are empty.
Advanced jQuery Exercises
- Fetch JSON data using
$.getJSON()
and display it in a table. - Create an accordion-style menu using
slideToggle()
. - Build a dynamic image carousel using
fadeIn()
andfadeOut()
. - Implement infinite scrolling for a list of items.
- Add a loading spinner while fetching data from a server.
- Create a sticky navigation bar that stays fixed on scroll.
- Validate an email address using a regular expression.
- Implement drag-and-drop functionality with jQuery UI.
- Create a sortable list using jQuery UI.
- Build a custom tooltip that appears on hover.
Bonus Suggestions
You can extend these exercises by adding:
- Combining effects, like fading and sliding together.
- Using Ajax to load content into a
<div>
dynamically. - Building small interactive applications like a calculator or a to-do list.