#Lesson 2 - jQuery Events
###Daily Objective
Students will be able to create interaction within their site using jQuery event handlers.
- An event handler is used to execute a body of code after an event has occured. A common kind of handler is a
click
handler.
- Do Now
- Exit Ticket
- Students will show progress toward reaching the objective based on their performance on the Exit Ticket.
- event handler
click
handlerhover
handlermouseover
handlerscroll
handler
- http://www.w3schools.com/jquery/jquery_events.asp
- http://www.w3schools.com/jquery/jquery_dom_get.asp
- http://www.w3schools.com/jquery/jquery_dom_set.asp
- http://www.w3schools.com/jquery/jquery_dom_add.asp
- http://www.w3schools.com/jquery/jquery_css.asp
- Attendance:
- Return reviewed Do Now and Exit Ticket from previous class.
- Do Now activity
Yesterday, we used jQuery to create a simple page. Today, we are going to use jQuery to create page interaction. Can somebody name some ways in which you interact with a webpage? [click, scroll, etc.]
An event handler is a piece of code that runs after an event has occured. Example of events include a key press on a keyboard and the scroll on a mouse.
A common kind of handler is a click
handler which runs after the mouse has been clicked over a certain element. Let's suppose we had HTML code like so:
<html>
<head>...</head>
<body>
<button class="btn">Click me!</button>
</body>
</html>
Clicking on the button will not do anything. Let's add a click handler to change that:
$(".btn").click(function()
{
alert("Yay! You clicked me.");
});
Clicking on the button will now trigger a pop-up window (or alert) with the following text: "Yay! You clicked me."
Now we're going to practice jQuery handlers together. Let's open the Cloud9 workspace "jQurey-practice" together.
Using a click
handler, make the image on the page change to a different image when clicked.
Create a new page in your workspace called day2.html
.
- Using HTML, place a button, an image, and some text on your site.
- Place a click handler on the button that displays an alert box when clicked.
- Use a
mouseover
handler to change the image when someone hovers their mouse over the image.
Bonus: Use a scroll
handler to change the text when someone scrolls over the image.
Note: Tags from the index page may need to be changed or added in order to not affect the layout og day2.html
Give the Exit Ticket.
Today, you learned about jQuery. This is important because jQuery enables us to dynamically interact with our HTML and CSS. Next, we will learn about interacting with jQuery project.
There is no homework for today's session.
- Review Do Now & Exit Ticket.
- Prepare for next lesson / hand off to next volunteer in rotation.