Interactive guide to learning jQuery with videos, exercises, and solutions
All videos organized by creation date (oldest to newest):
Generating tables from data
Organizing resume code into separate scripts
01-FromJavaScriptTojQuery/03-manipulating_the_dom/
02-jQueryIntroduction/
// Example jQuery inclusion in HTML <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="script.js"></script>
Video Solution: Review video_solution folder files to see jQuery selector examples
Challenge: Try the challenge_solution to practice selectors independently
// jQuery Selectors Examples
$('#myId') // Select by ID
$('.myClass') // Select by Class
$('p') // Select by Tag
$('div p') // Descendant Selector
$('div > p') // Child Selector
$('input[type=text]') // Attribute Selector
Video Solution: Review video_solution folder files to see how to change HTML/CSS with jQuery
Challenge: Try the challenge_solution to practice HTML/CSS manipulation
// jQuery HTML/CSS Methods
$('#element').html() // Get HTML content
$('#element').html('New Content') // Set HTML content
$('#element').text() // Get text content
$('#element').text('New Text') // Set text content
$('#element').css('color') // Get CSS property
$('#element').css('color', 'red') // Set CSS property
$('#element').addClass('newClass')
$('#element').removeClass('oldClass')
$('#element').toggleClass('toggleClass')
Video Solution: Review files in video_solution to see first jQuery scripts
Challenge: Try challenge_solution to practice writing jQuery scripts from scratch
// Basic jQuery Document Ready Function
$(document).ready(function() {
// Your jQuery code here
$('button').click(function() {
$('p').hide();
});
});
// Or shorthand version
$(function() {
// Your jQuery code here
});
03-jQueryEvents/
Video Solution: Review video_solution files to see jQuery event handling
Challenge: Try challenge_solution to practice event handling
// jQuery Event Handling
$('button').click(function() {
// Handle click
});
$('input').keydown(function(event) {
// Handle keydown
});
$('form').submit(function(event) {
event.preventDefault(); // Prevent form submission
// Handle form submission
});
// Event delegation
$(document).on('click', '.dynamic-button', function() {
// Handle clicks on dynamically added elements
});
Challenge: Work with challenge_solution files to practice jQuery built-in effects
// jQuery Effects
$('#element').hide();
$('#element').show();
$('#element').toggle();
$('#element').fadeIn();
$('#element').fadeOut();
$('#element').fadeToggle();
$('#element').slideUp();
$('#element').slideDown();
$('#element').slideToggle();
// With duration
$('#element').fadeIn(1000); // 1 second
// With callback
$('#element').fadeOut(function() {
alert('Fade out completed!');
});
Video Solution: Review video_solution files to see jQuery method chaining
Challenge: Try challenge_solution to practice method chaining
// jQuery Method Chaining
$('#element')
.css('color', 'blue')
.fadeOut(1000)
.delay(500)
.fadeIn(1000)
.addClass('highlight');
// Each method returns a jQuery object, allowing chaining
Challenge: Review challenge_solution files to understand "this" in jQuery
Additional Exercises: Explore hiding_paragraphs, if_statements, mouseenter_and_mouseleave, and red_and_black_boxes
// jQuery "this" keyword
$('button').click(function() {
// "this" refers to the clicked button element
$(this).css('background-color', 'red');
// Find elements relative to "this"
$(this).siblings().hide();
$(this).parent().addClass('active');
});
04-jQuery-TraversingMtDOM/
// jQuery Traversing Methods
$('#start').parent() // Get direct parent
$('#start').parents() // Get all ancestors
$('#start').parents('.class') // Get specific ancestor
$('#start').children() // Get direct children
$('#start').find('.class') // Find descendants
$('#start').siblings() // Get siblings
$('#start').next() // Get next sibling
$('#start').prev() // Get previous sibling
By the end of this lab, you should be able to: