jQuery: Introduction
ATLS 3020 - Digital Media 2 Week 8 - Day 1
jQuery: Introduction ATLS 3020 - Digital Media 2 Week 8 - Day 1 - - PowerPoint PPT Presentation
jQuery: Introduction ATLS 3020 - Digital Media 2 Week 8 - Day 1 Announcements March Mayhem BTU Lab Open House Tuesday, 5-6:30 ATLAS BTU Lab (ENVD 234) Toy Stories: Invention to Creation Wed, 4:3-6 ATLS 100 Stay and Play 6-7
ATLS 3020 - Digital Media 2 Week 8 - Day 1
March Mayhem
Tuesday, 5-6:30 ATLAS BTU Lab (ENVD 234)
Wed, 4:3-6 ATLS 100 Stay and Play 6-7 ATLS Lobby
Wed, 10:30p-12 ATLS 100
Thurs, 5-6 ATLS 204
Thurs, 6-8 ATLAS Black Box theater
Fri, 4-5:30 ATLAS Black Box theater Community Gathering 5:30-7
○ Selecting elements ○ Calling Functions ○ Handling Events
Include a link to the file from an
Pros: webpage will load faster on server Cons: must be connected to the internet
Download the file and include it in your webpage files Pros: no internet connection required Cons: webpage might load slower
<head> // meta, title, css <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script> <script> $(document).ready(function() { // your javascript/jQuery code }); </script> </head> HTML
This is showing adding jQuery with an externally hosted file. You can always go to this url, download the file, save it within your web files, and link to the local javascript file.
<div id="banner"></div> <div class="red"></div> <a href="">Link 1</a> <a href="">Link 2</a> HTML var banner_div = document.getElementById("banner"); Javascript $("#banner") jQuery var banner_div = document.getElementsByClass("red"); Javascript $(".red") jQuery
jQuery can select one or more elements with the jQuery object:
$("selector")
“selector” helps identify the element you want to select
jQuery functions manipulate the selected element:
$('selector').function();
$("#banner").html("<h1>Hello class</h1>"); jQuery $("#banner").text("Hi class"); jQuery $("#banner").append("<p>There are errors </p>"); jQuery $("#banner").remove(); jQuery
Changes the HTML inside of the “banner” id Changes the text inside of the “banner” id Add HTML to the end of the HTML inside of the “banner” id Will delete the “banner” id all together
jQuery functions can handle common events: $('selector').event();
$("#banner").hover(function1, function2, ...); jQuery $("#banner").hide(); jQuery $("#banner").show(); jQuery $("#banner").toggle(); jQuery
Combines mouseover and mouseout events Hides the “banner” id Shows the “banner” id Alternates between hiding and showing the “banner” id
$("#banner").click(function1, function2, ...); jQuery
Creates a click event
jQuery provides functions for common effects: $('selector').effect();
$("#banner").fadeIn(); jQuery $("#banner").fadeOut(); jQuery $("#banner").slideUp(); jQuery $("#banner").slideDown(); jQuery
Makes a hidden element fade into view Hides an element by fading it out Makes a visible element side out of view Makes a hidden element slide into view
1. Create a webpage with a button. (This can be a div, button, image, or whatever you want, it just has to be clickable by the user). Put an id on that button. 2. Access that button with a jQuery selector. 3. Add a click event to that button. Inside of the click event, call a function 4. Create a function (with the same name from step #3) that will change an element on the page (with a function, event, or effect). 5. Repeat steps 1-4 five more times. Make sure you have created new buttons and functions each time. Each function can change the same element, but you much use different functions/events/effects for each function. In the end you should have 6 buttons that, when clicked, make 6 different types of changes to your webpage.