JQuery CS 268. What is jQuery? From their web site:

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Samsung Smart TV is a web-based application running on an application engine installed on digital TVs connected to the Internet.
JavaScript and AJAX Jonathan Foss University of Warwick
CT-376 jQuery Most popular javascript library today Latest version:
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
JQuery A Javascript Library Hard things made eas(ier) Norman White.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
The Web Warrior Guide to Web Design Technologies
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
JQuery. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing and manipulation event handling.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
Getting Started.  jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
JavaScript & jQuery the missing manual Chapter 11
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
Bill's Amazing Content Rotator jQuery Content Rotator.
Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
JavaScript, Fourth Edition
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to JavaScript 41 Introduction to Programming the WWW I CMSC Winter 2004 Lecture 17.
Animation & Effects Using JQuery. What is jQuery? jQuery is a lightweight, JavaScript library. The purpose of jQuery is to make it much easier to use.
JQuery Youn-Hee Han
. Taught by: Muhammad Ali Baloch midahot. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between.
Use CSS to Implement a Reusable Design Selecting a Dreamweaver CSS Starter Layout is the easiest way to create a page with a CSS layout You can access.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
JavaScript Library. What is jQuery jQuery is a lightweight JavaScript library. The purpose is to make it easier to use JavaScript code on your website.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Creating Dynamic Webpages
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
Dawn Pedersen. What is JavaScript? JavaScript is the basis for both jQuery and Spry applications JavaScript is referred to as a client-side scripting.
IS2802 Introduction to Multimedia Applications for Business Lecture 07: Introduction to jQuery Rob Gleasure
Unit 13 –JQuery Basics Instructor: Brent Presley.
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
AJAX. Overview of Ajax Ajax is not an API or a programming language Ajax aims to provide more responsive web applications In normal request/response HTTP.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
Understanding JavaScript and Coding Essentials Lesson 8.
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
Chapter 1 Murach's JavaScript and jQuery, C1© 2012, Mike Murach & Associates, Inc.Slide 1.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
JQUERY AND AJAX
JQuery Tutorial. What is jQuery jQuery is a JavaScript Library The purpose of jQuery is to make it much easier to use JavaScript on your website JavaScript.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Web Programming Java Script-Introduction. What is Javascript? JavaScript is a scripting language using for the Web. JavaScript is a programming language.
.. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between HTML and JavaScript. The jQuery library.
JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was.
COM621: Advanced Interactive Web Development Lecture 6 – JavaScript (cont.)
Section 10.1 Define scripting
Not a Language but a series of techniques
Intro to JavaScript CS 1150 Spring 2017.
Introduction to Web programming
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
E-commerce Applications Development
Presentation transcript:

jQuery CS 268

What is jQuery? From their web site:

Is jQuery the only one? (No) From:

jQuery architecture Finds objects in the DOM/HTML using CSS style syntax. Core of jQuery is a group of functions designed to create/edit/delete the array of elements Also provides many methods for editing the basic components of elements like.css and.attr

What can jQuery do? Demos (from jQuery's site): Tutorials (from jQuery's site):

What is the jQuery dollar sign $ ? It is an identifier. You can think of it as a function name. You can use jQuery in place of the $ sign  but since most of us are lazy we use the $  For example these are equivalent lines of code: jQuery("#divTest1").text("Hello, world!"); $("#divTest1").text("Hello, world!");

What is the jQuery dollar sign $ ? The $ (or jQuery) function returns objects Therefore you can use. (dot) notation to access additional methods/functions applicable to the returned object. jQuery("#divTest1").text("Hello, world!"); $("#divTest1").text("Hello, world!");

jQuery allows easy access to Elements # used to reference elements with an id attribute. (dot or period) is used to reference elements with class attributes Omit # and. and you are searching for all elements of the same type, like div or table or img or... jQuery("#divTest1").text("Hello, world!"); $("#divTest1").text("Hello, world!");

jQuery ready event jQuery assumes you often want to execute code after a page loads. JavaScript can do this if called from a body tag's onload event  But this requires all images to finish loading jQuery's ready event is executed after all page elements (tags) are loaded - BUT before images are completely down loaded.  Allows quicker code execution

jQuery tutorials usually start here With the.ready event JQuery function documentReady() { $("#divTest1").text("Hello, world!"); } $(document).ready(documentReady); Calls documentReady after elements/tags are loaded

jQuery ready event shortcut The jQuery ready event is used often – so the jQuery developers decided to allow shorthand notation for it  Send an "anonymous" function as a parameter to it  An anonymous function does not have a name // use an anonymous function $(document).ready( function() { $("#divTest2").text("Hello, world!"); } );

jQuery ready event shortcut The code is often formatted like this (same code as in previous slide // use an anonymous function $(document).ready(function() { $("#divTest2").text("Hello, world!"); });

Even shorter notation for same thing Omit the (document).ready – default assumes this is there.  The jQuery crowd likes shortcuts! $(function() { $("#divTest2").text("Hello, world!"); });

Fade In

Fade In several boxes

Toggle fade in and out

Slide box up (till disappears)

Slide box up and down

Slide box down

Adding event handlers using jQuery Easier than slide 133's approaches shown in previous JS slideshow

Hiding text

Picture Galleries the jQuery Way! Using jQuery simplies the "custom" gallery you created in assignment1 Combines jQuery event handling with jQuery effects

The Gallery's HTML File Picture Gallery San Juan Mountains Colorado Close

JS File Using jQuery for Gallery $(function() { $("#popupphoto").click(function() { $("#popupphoto").fadeOut(1000); }); $(".image").mouseover(function() { $(this).css("border", "3px solid #9F0"); }); $(".image").mouseout(function() { $(this).css("border", "3px solid #000000"); }); // continued on next slide Assign event handlers here rather than in the HTML file

JS File Using jQuery for Gallery // continued from previous slide $(".image").click(function() { var path = $(this).attr("src"); path = getLargePhotoPath(path); $("#imgphoto").attr("src", path); $("#popupphoto").slideDown(1000); $("#filename").text(getFilename(path)); }); getLargePhotoPath and getFilename are short string handling functions to get the path to the large photos from the current thumbnail's path and to return the filename to display in the pop up photo this refers to clicked image object

Still not quite done... Previous gallery example issue:  After displaying large photo If close large photo first (has a fade out effect) clicking thumbnail allows the slide down effect (this is also good) Click another thumbnail without closing the larger photo  Next image is displayed without the slide down effect (not good – want to retain the fade out and slide in effects) Solution adds a bit more code...

Solution Modify the thumbnail image's click event $(".image").click(function() {  Check to see if the larger pop up photo is displayed: if($("#popupphoto").is(":visible")) { If it is, add code to fade out the large photo before sliding in the new photo  Not quite as easy as it might look .fadeOut and.slideDown allow following lines of code to run while the fade or slide is happening.  Need a way to ensure the fadeOut finishes before starting the slideDown!

Solution (continued).fadeOut and.slideDown have an optional second parameter  Second parameter is a function called after the fade or slide is finished.  Use an anonymous function to slide in the new photo after the fade is finished! $("#popupphoto").fadeOut(1000, function() { // code to slide in };); Using the name of a normal function as the second parameter seems like it should work but it doesn’t. The function gets called immediately without waiting for the effect to complete. Use an anonymous function.

var showFileName = true; // = true to show the filename in the popup photo, = false to hide it $(function() { // I'm not showing all the event handlers from slides 25 and 26 // I'm only showing how to modify the $(".image").click(function() { code // but the other code is still needed here. $(".image").click(function() { var path = getLargePhotoPath($(this).attr("src")); if($("#popupphoto").is(":visible") == true) { fadeThenSlideIn(path); } else { slideIn(path); } }); function fadeThenSlideIn(path) { $("#popupphoto").fadeOut(1000, function() { $("#imgphoto").attr("src", path); $("#popupphoto").slideDown(1000); if(showFileName == true) { $("#filename").text(getFilename(path)); } }); } function slideIn(path) { $("#imgphoto").attr("src", path); $("#popupphoto").slideDown(1000); if(showFileName == true) { $("#filename").text(getFilename(path)); }

AJAX AJAX – Asynchronous JavaScript and XML  XML – eXtensible Markup Language markup language for encoding data opening and closing tags used to identify data semantics like html but you get to define the tags and their meanings  AJAX allows updating portions of a web page with additional detail without reloading "all" of the web page.

AJAX

Initial web page has one or more sections within it with content derived from other web pages  HTTPRequest retrieves this data Makes Drill Down (Master Detail) pages easy to implement

jQuery AJAX Simplifies AJAX and creates cross browser compatible code

HTML fragment – not a complete page

Dynamically generated content

Another jQuery shortcut The first code example does the same thing the second one is doing (with less code) $("#orderInfo").html(ajax_load).load(loadUrl).css("display", "none").css("top", 40).fadeIn(500); $("#orderInfo").html(ajax_load).load(loadUrl); $("#orderInfo").html(ajax_load).css("display", "none"); $("#orderInfo").html(ajax_load).css("top", 40); $("#orderInfo").html(ajax_load).fadeIn(500); Same as: