M. Taimoor Khan Courtesy: Norman White.

Slides:



Advertisements
Similar presentations
Diego Guidi - DotNetMarche. DOM tree is clunky to use No multiple handlers per event No high-level functions Browser incompatibilities = jQuery to the.
Advertisements

The jQuery library. What is jQuery ? A javascript lightweight library Is very easy to use Is powerful Is cross-browser compatible Downloadable from jQuery.com,
CT-376 jQuery Most popular javascript library today Latest version:
SE-2840 Dr. Mark L. Hornick1 jQuery. jQuery is a library of JavaScript functions Helps minimize the amount of JavaScript you have to write in order to:
JQuery A Javascript Library Hard things made eas(ier) Norman White.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part II Jongwook.
Basic Animation: JavaScript and jQuery.  1 week from today (next Tuesday)  You're allowed to bring a 3x5 card with anything written on it that you want.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I JQuery Part I Jongwook Woo,
CS428 Web Engineering Lecture 15 Introduction to Jquery.
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 (
JQuery CS 268. What is jQuery? From their web site:
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
Nguyen Ich Cuong.  Course duration: 45’  Purpose: Present Introduction to JQuery  Targeted attendees: NICorp Trainee  Tests/quiz: Yes - 10’
JavaScript & jQuery the missing manual Chapter 11
By Jon Marozick.  JavaScript toolkit  Aims to change the way developers think  jQuery philosophy  Find some HTML  Do something to it.
JQuery March 09 th,2009 Create by
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Jquery Nasrullah. Jquery jQuery is a JavaScript Library. jQuery greatly simplifies JavaScript programming. jQuery is easy to learn.
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.
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
CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Browser scripting jQuery Edited by: Trần Thị Mỹ Dung Ref:w3schools.com.
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.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
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.
Web Programming Language Week 9 Dr. Ken Cosh Introducing jQuery.
Creating Dynamic Webpages
JQuery and AJAX WEB Technologies : PHP Programming Language.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
IS2802 Introduction to Multimedia Applications for Business Lecture 07: Introduction to jQuery Rob Gleasure
Unit 13 –JQuery Basics Instructor: Brent Presley.
Web Technologies Lecture 8 JQuery. “A fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax.
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.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
KAPITA SELEKTA INFORMATIKA Lasmedi Afuan, ST.M.Cs.
Selectors & Events. What do Selectors do? What do Selectors do? Selectors allow you to manipulate DOM elements as a group or as a single node. This allows.
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.
Engr. Md. Nazim Uddin M.Sc. Eng. (CSE), B.Sc. Engg. (CSE), MIEB Cell: Website:
JQuery The Write Less, Do More, JavaScript Library.
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
JQuery Element & Attribute Selectors, Events, HTML Manipulation, & CSS Manipulation.
JQuery.
What is jQuery?.
CS7026 jQuery Effects.
-By Yogita Nirmal.
Tek Raj Chhetri Code for Humans not for machine.
jQuery A Javascript Library Hard things made eas(ier)
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
JQuery Basics 소속 / 작성자 이 문서는 나눔글꼴로 작성되었습니다. 설치하기.
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
JQUERY Online TRAINING AT GOLOGICA
The Cliff Notes Version
JQuery with ASP.NET.
jQuery A Javascript Library Hard things made eas(ier)
Web Programming Language
SEEM4570 Tutorial 5: jQuery + jQuery Mobile
Javascript and JQuery SRM DSC.
E-commerce Applications Development
Document Object Model.
Web Programming Language
JQuery.
Presentation transcript:

M. Taimoor Khan Courtesy: Norman White

jQuery  Code less do more  Code is simpler and more manageable  Less prune to errors  Support different browser types  (Fairly) easy to learn  You should try all the examples on Or take the code Academy JQuery course.

Simple example //include remote jquery library //or save it in a.js file and include it as a local file $(document).ready(function() { $("p").click(function() { $(this).hide(); }); }); If you click on me, I will disappear.

jQuery Overview What is jQuery? jQuery is a library of JavaScript Functions. jQuery is a lightweight "write less, do more" JavaScript library. The jQuery library contains the following features: – HTML element selections – HTML element manipulation – CSS manipulation – HTML event functions – JavaScript Effects and animations – HTML DOM traversal and modification – AJAX – Utilities

Using jQuery Just include the library

Simple jQuery Click button to hide all paragraphs $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); This is a heading This is a paragraph. This is another paragraph. Click me and things will be hidden

jQuery Syntax Examples $ indicates a jQuery statement (Note CSS Style References) $(this).hide() Demonstrates the jQuery hide() method, hiding the current HTML element. $(this).hide() $("#test").hide() Demonstrates the jQuery hide() method, hiding the element with id="test". $("#test").hide() $("p").hide() Demonstrates the jQuery hide() method, hiding all elements. $("p").hide() $(".test").hide() Demonstrates the jQuery hide() method, hiding all elements with class="test". $(".test").hide()

Syntax SELECT some HTML Elements and perform some action on them $(selector).action() Usually define functions only after the document is finished loading, otherwise elements may not be there. $(document).ready(function(){ // jQuery functions go here... });

jQuery Selectors  jQuery Element Selectors  jQuery uses CSS selectors to select HTML elements.  $("p") selects all elements.  $("p.intro") selects all elements with class="intro".  $("p#demo") selects all elements with id="demo".

jQuery Attribute Selectors jQuery uses XPath expressions to select elements with given attributes. $("[href]") select all elements with an href attribute. $("[href='#']") select all elements with an href value equal to "#". $("[href!='#']") select all elements with an href attribute NOT equal to "#". $("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg".

CSS Selectors  jQuery CSS Selectors  jQuery CSS selectors can be used to change CSS properties for HTML elements.  The following example changes the background- color of all p elements to yellow:  Example  $("p").css("background-color","yellow");

More Examples Syntax Description $(this) Current HTML element $("p") All elements $("p.intro") All elements with class="intro" $("p#intro") All elements with id="intro" $("p#intro:first") The first element with id="intro" $(".intro") All elements with class="intro" $("#intro") The first element with id="intro" $("ul li:first") The first element of the first $("ul li:first-child") The first element of every $(“ul li:nth-child(3)” The third element of every $("[href$='.jpg']") All elements with an href attribute that ends with ".jpg" $("div#intro.head") All elements with class="head" inside a element with id="intro"

Event Functions $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); This is a heading This is a paragraph. This is another paragraph. Click me

Sample Events Event Method Description $(document).ready(function) Binds a function to the ready event of a document (when the document is finished loading) $(selector).click(function) Triggers, or binds a function to the click event of selected elements $(selector).dblclick(function) Triggers, or binds a function to the double click event of selected elements $(selector).focus(function) Triggers, or binds a function to the focus event of selected elements $(selector).mouseover(function) Triggers, or binds a function to the mouseover event of selected elements.

Effects Examples jQuery hide() Demonstrates a simple jQuery hide() method. jQuery hide() jQuery hide() Another hide() demonstration. How to hide parts of text. jQuery hide() jQuery slideToggle() Demonstrates a simple slide panel effect. jQuery slideToggle() jQuery fadeTo() Demonstrates a simple jQuery fadeTo() method. jQuery fadeTo() jQuery animate() Demonstrates a simple jQuery animate() method. jQuery animate()

jQuery Hide and Show With jQuery, you can hide and show HTML elements with the hide() and show() methods: Example $("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); }); Note: These can be very useful on mobile devices

Hide and show speed  $(selector).hide(speed,callback)  $(selector).show(speed,callback)  $("button").click(function(){ $("p").hide(1000); });

Toggle Between show and hide $(selector).toggle(speed,callback) $("button").click(function(){ $("p").toggle(); });

jQuery Slide - slideDown, slideUp, slideToggle The jQuery slide methods gradually change the height for selected elements. jQuery has the following slide methods: $(selector).slideDown(speed,callback) $(selector).slideUp(speed,callback) $(selector).slideToggle(speed,callback) The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds. The callback parameter is the name of a function to be executed after the function completes.

Slide Examples $(".flip").click(function(){ $(".panel").slideDown(); }); $(".flip").click(function(){ $(".panel").slideUp() }) $(".flip").click(function(){ $(".panel").slideToggle(); });

  $(document).ready(function(){  $(".flip").click(function(){  $(".panel").slideToggle("slow");  });   div.panel,p.flip  {  margin:0px;  padding:5px;  text-align:center;  background:#e5eecc;  border:solid 1px #c3c3c3;  }  div.panel  {  height:120px;  display:none;  }   Because time is valuable, we deliver quick and easy learning.  At Stern, you can study everything you need to learn, in an accessible and handy format.   Show/Hide Panel 

jQuery Fade - fadeIn, fadeOut, fadeTo The jQuery fade methods gradually change the opacity for selected elements. jQuery has the following fade methods: $(selector).fadeIn(speed,callback) $(selector).fadeOut(speed,callback) $(selector).fadeTo(speed,opacity,callback) The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds. The opacity parameter in the fadeTo() method allows fading to a given opacity. The callback parameter is the name of a function to be executed after the function completes.

Custom Animations The syntax of jQuery's method for making custom animations is: $(selector).animate({params},[duration],[easing],[ callback]) The key parameter is params. It defines the CSS properties that will be animated. Many properties can be animated at the same time: animate({width:"70%",opacity:0.4,marginLeft:"0.6in",fontSize:"3 em"}); The second parameter is duration. It specifies the speed of the animation. Possible values are "fast", "slow", "normal", or milliseconds.

Animation Example $(document).ready(function(){ $("button").click(function(){ $("div").animate({height:300},"slow"); $("div").animate({width:300},"slow"); $("div").animate({height:100},"slow"); $("div").animate({width:100},"slow"); }); });

$(document).ready(function(){ $("button").click(function(){ $("div").animate({left:"100px"},"slow"); $("div").animate({fontSize:"3em"},"slow"); }); });

Callback Functions Function called after action is completed $("p").hide(1000,function(){ alert("The paragraph is now hidden"); }); Instead of $("p").hide(1000); alert("The paragraph is now hidden"); In 2 nd example the alert will show before the paragraph is hidden, since the alert happens immediately and the hide takes 1 second. Calling the alert from a callback function ensures that it won’t happen until the paragraph is hidden.

Changing HTML Content $(selector).html(content) The html() method changes the contents (innerHTML) of matching HTML elements. $("p").html(“Stern is the best"); Will change all html within a tag to “Stern is the best”

Example $(document).ready(function(){ $("button").click(function(){ $("p").html(“Stern is the best"); }); This is a heading This is a paragraph. This is another paragraph. Click me Wait for document to load Add a button to change All “p” elements to “Stern is the best” When clicked.

Can also append or prepend content Adding HTML content $(selector).append(content)  The append() method appends content to the inside of matching HTML elements. $(selector).prepend(content)  The prepend() method "prepends" content to the inside of matching HTML elements.

After and Before $(selector).after(content) The after() method inserts HTML content after all matching elements. $(selector).before(content) The before() method inserts HTML content before all matching elements.

Many, Many HTML functions Look at full reference

CSS Methods Method Description addClass()addClass() Adds one or more classes to selected elements css()css() Sets or returns one or more style properties for selected elements hasClass()hasClass() Checks if any of the selected elements have a specified class height()height() Sets or returns the height of selected elements offset()offset() Sets or returns the position (relative to the document) for selected elements offsetParent()offsetParent() Returns the first parent element that is positioned position()position() Returns the position (relative to the parent element) of the first selected element removeClass()removeClass() Removes one or more classes from selected elements scrollLeft()scrollLeft() Sets or returns the horizontal position of the scrollbar for the selected elements scrollTop()scrollTop() Sets or returns the vertical position of the scrollbar for the selected elements toggleClass()toggleClass() Toggles between adding/removing one or more classes from selected elements width() Sets or returns the width of selected elementswidth()

jQuery AJAX Asynchronous Javascript and XML AJAX Allows javascript to dynamically communicate with a server without reloading the page. jQuery provides a rich set of methods for AJAX web development. With jQuery AJAX, you can request TXT, HTML, XML or JSON data from a remote server using both HTTP Get and HTTP Post. And you can load remote data directly into selected HTML elements of your web page! This is the magic that allows for web pages to dynamically change parts of their content instead of having to reload the whole page. No more click submit and wait for new page. Example: Google Earth, Google maps More map tiles are loaded in the background while you look at part of the map, so that when you move, the next area is already loaded.

jQuery load method The jQuery load() method is a simple (but very powerful) AJAX function. It has the following syntax: $(selector).load(url,data,callback) Use the selector to define the HTML element(s) to change, and the url parameter to specify a web address for your data.

jQuery load $(document).ready(function(){ $("button").click(function(){ $("div").load('test1.txt'); }); Let AJAX change this text Change Content Load ‘test1.txt’ from same Directory as the web page And replace div content With contents of “test1.txt”

jQuery AJAX Many functions to move data back and forth between the server and PARTS of the web page. Very powerful Need these features to provide good user experience on mobile devices

Conclusion  jQuery provides a wide range of functionality that makes very advanced capabilities available to developers who know a little javascript, html and css.  jQuery mobile extends those capabilities for mobile devices by adding a set of mobile features  Makes it easy(?) to develop cross platform mobile apps that are fairly sophisticated without using the SDK tools for the mobile device.  jQuery mobile uses Phonegap to access mobile device capabilities like geolocation, cameras, accelerometer, etc.  jQuery mobile includes capabilities to use AJAX to move data between the mobile device and a remote server.  But next we do PHP.