At the end of this class, you will be able to:
click
dblcode
mouseenter
mouseleave
keypress
keydown
keyup
submit
change
focus
blur
resize
scroll
Select the DOM Element:
const button = document.querySelector(‘.submitBtn’);
Attach event listener to DOM element:
Select the DOM Element:
const button = document.querySelector(‘.submitBtn’);
Attach event listener to DOM element:
Select the DOM Element:
const button = document.querySelector(‘.submitBtn’);
Attach event listener to DOM element:
Select the DOM Element:
const button = document.querySelector(‘.submitBtn’);
Attach event listener to DOM element:
click
dblcode
mouseenter
mouseleave
keypress
keydown
keyup
submit
change
focus
blur
resize
scroll
Select the DOM Element:
const button = document.querySelector(‘.submitBtn’);
Attach event listener to DOM element:
Open up: 00-events-codealong
Key Objective
Type of Exercise
Location
Timing
8 mins |
|
event
or e
submitButton.on('click', (event) => {
console.log(event); // Access to event object
});
preventDefault()
submitButton.on('click', (event) => {
event.preventDefault();
});
Open up: 02-event-object-codealong
Type of Exercise
Location
Timing
3 mins |
|
jQuery allows us to keep using the CSS-style selectors with a more concise syntax:
jQuery statements for DOM manipulation are more concise than Vanilla JavaScript:
JQUERY |
---|
✅ Write less code |
✅ Plenty of tutorials / examples |
VANILLA JAVASCRIPT |
---|
✅ Better performance |
✅ Faster |
scripts
or js
.
<body>
<!-- HTML content goes here -->
<script src="js/main.js"></script>
</body>
.js
extension (example: main.js
).</body>
tag and after the <script>
<body>
<!-- HTML content goes here -->
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/main.js"></script>
</body>
.js
extension (example: main.js
).</body>
tag and after the <script>
<script>
tag before the main.js
file (the order matters).
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
CSS | JQUERY | |
---|---|---|
ELEMENT |
|
|
ID |
|
|
CLASS |
|
|
NESTED SELECTOR |
|
|
Selecting elements with vanilla JavaScript returns an element reference (querySelector
) or a collection of element references (querySelectorAll
)
querySelector('selector')
<element reference>
Selecting elements with jQuery returns a jQuery object, which is one or more element references packaged with jQuery methods and properties.
$('selector')
{
element reference
methods
properties
}
A typical naming convention is to include $
at start of variable name to indicate that its value is a jQuery object.
const $openTab = $('.open');
Open up: 04-jquery-statements-codealong
METHODS | EXAMPLES |
---|---|
|
|
|
|
|
|
|
|
METHODS | EXAMPLES |
---|---|
|
|
|
|
|
|
METHODS | EXAMPLES |
---|---|
|
|
|
|
|
|
Open up: 04-jquery-statements-codealong
Key Objective
Type of Exercise
Location
Timing
5 mins |
|
METHODS | EXAMPLES |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Open up: 04-jquery-statements-codealong
We use the on()
method to handle events in jQuery:
We use the on()
method to handle events in jQuery:
We use the on()
method to handle events in jQuery:
We use the on()
method to handle events in jQuery:
click
dblcode
mouseenter
mouseleave
keypress
keydown
keyup
submit
change
focus
blur
resize
scroll
We use the on()
method to handle events in jQuery:
Open up: 06-jquery-events-codealong
Key Objective
Type of Exercise
Location
Timing
5 mins |
|
At the end of this class, you will be able to:
(Lesson #09)