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,

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

JavaScript – Quiz #8 Lecture Code:
Getting Started with jQuery. 1. Introduction to jQuery 2. Selection and DOM manipulation Contents 2.
By ishaq shinwari.  jQuery is a lightweight, "write less, do more", JavaScript library.  The purpose of jQuery is to make it much easier to use JavaScript.
Programming Club IIT Kanpur. Work environment Before you begin coding,always set up your work environment to your needs IDE Notepad++ Sublime Text 2.
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.
Introduction to jQuery Giuseppe Attardi Università di Pisa Some slides from: BreadFish.
JQuery The Way to JavaScript and Rich Internet Applications.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
Building a Rich Internet Application with jQuery Ben Dewey twentysix New York Fill this space.
School of Computing and Information Systems CS 371 Web Application Programming jQuery.
Event Handling. Overview How to listen (and not listen) for events Creating a utility library (and why you should) Typology of events Pairing event listeners.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
 jQuery Mobile An Introduction. What is jQuery Mobile  A framework built on top of jQuery, used for creating mobile web applications  Designed to make.
M. Taimoor Khan Courtesy: Norman White.
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’
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.
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.
LOGO sparcs.org 1 jQuery Tutorial Presenter ㅎㅇㅎㅇ.
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.
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
Host Objects: Browsers and the DOM
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.
CHAPTER 7 JQUERY WHAT IS JQUERY? jQuery is a script. It is written in JavaScript.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
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.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Engr. Md. Nazim Uddin M.Sc. Eng. (CSE), B.Sc. Engg. (CSE), MIEB Cell: Website:
JQuery The Write Less, Do More, JavaScript Library.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 5 Host Objects: Browsers.
JQuery Element & Attribute Selectors, Events, HTML Manipulation, & CSS Manipulation.
JQuery.
CS7026 jQuery Effects.
-By Yogita Nirmal.
Tek Raj Chhetri Code for Humans not for machine.
Intro to jQuery jQuery is a popular, and extensible, JavaScript library Supports … DOM manipulation CSS manipulation HTML event methods Effects & animations.
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
JQUERY Online TRAINING AT GOLOGICA
CS3220 Web and Internet Programming Client-Side JavaScript and jQuery
jQuery A Javascript Library Hard things made eas(ier)
Events.
Introduction to jQuery
JQuery Animation for beginners NOTES?!.
Web Programming Language
E-commerce Applications Development
Web Programming Language
JavaScript and Events CS Programming Languages for Web Applications
Chengyu Sun California State University, Los Angeles
CS7026 jQuery Events.
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
JavaScript and Events CS Programming Languages for Web Applications
JQuery.
Presentation transcript:

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, 2 versions (a production version and a development version)

jQuery features DOM structure/nodes and CSS manipulation CSS-like selectors Strong event handling support Effects, transitions and animations AJAX and simple data support Javascript utility methods

Linking to the jQuery library Use a downloaded version: Use an online version:

jQuery code location $(document).ready(function() { … jquery code.. }); the document ready event is fired when the DOM is fully loaded a short-hand alternative: $(function() { … jquery code.. });

jQuery method call syntax methods called on jQuery selections are in the $.fn namespace, and automatically receive and return the selection as this. Ex.: $(“p”).html(“Test paragraph”); $(“div#id”).remove(); methods in the $ namespace are generally utility-type methods, and do not work with selections Ex.: $.each([ "foo", "bar", "baz" ], function( idx, val ) { console.log( "element " + idx + " is " + val ); });

Methods called on jQuery selections Simple syntax: $(selector).action(params) Ex.: $(“div.class1”).hide(); Chain syntax: $(selector).action1(params).action2(params)… Ex.: $( "#content" ).find( "h3" ).html( "new text for the h3!" ); or $( "#content" ).find( "h3" ).html( "new text for the third h3!" ); these methods return the jQuery object

jQuery selectors Has a CSS-like syntax for selectors: $(“*”) – selects all elements $(“#someid”) – selects element with ID attribute=someid $(“.someclass”) – selects element with Class attribute=someclass $(“div”) – selects all the DIV elements $(“.class1.class2”) – selects elements with classes class1 and class2 $(“div p”) – selects all elements that are inside a $(“p:first”) – selects the first p element $(“p:last”) – selects the last p element $(“tr:even”) – selects all even tr elements $(“tr:odd”) – selects all odd tr elements $(“ul li:eq(2)”) - selects the 3rd element from an unordered list $(“:contains(‘some text’)”) – select all elements containing the text

jQuery Selectors (2) $(this) – selects the current html element $(“#div1 ul li.innerdiv”) – compound CSS selector $(“h1,h2,h3”) – selects all h1, h2 or h3 elements $(“div:first-child”) – selects div elements that are the first child of their parents $(“div:first-of-type”) - selects div elements that are the first div child of their parents $(“div:last-child”) - selects div elements that are the last child of their parents $(“div:last-of-type”) - selects div elements that are the last div child of their parents $(“div:nth-child(3)”) - selects div elements that are the 3rd child of their parents $(“div:nth-of-type(3)”) - selects div elements that are the 3 rd div child of their parents $(“div > p”) – selects elements p which are direct child of a div

jQuery Selectors (3) $("div + p") – selects p elements that are the nearest siblings of a div element $("div ~ p") – selects p elements that are siblings of div elements $("ul li:eq(3)") – selects list elements with a list index of 3 $("ul li:gt(3)") – selects list elements with a list index greater than 3 $("ul li:lt(3)") – selects list elements with a list index less than 3 $(“[attribute]”) – selects elements with a specific attribute $(“[attribute=value]”) – selects elements having an attribute equal to a specific value $(“[attribute!=value]”) - selects elements having an attribute different than a specific value $(“[attribute$=value]”) - selects elements with an attribute ending with a specific value $(“[attribute^=value]”) - selects elements with an attribute starting with specific value $(“[attribute*=value]”) – attribute contains value

jQuery events has support for most html events mouse events: click(), dblclick(), focus(), focusin(), focusout(), blur(), hover(), mousedown(), mouseenter(), mouseleave(), mousemove(), mouseout(), mouseover(), mouseup() keyboard events: keypress(), keyup(), keydown() form events: submit(), change() window events: load(), resize(), ready(), scroll(), unload()

Binding events to handling functions $(selector).event(function() { …. }); Ex.: $(“div”).dblclick(function() { $(this).hide(); }); $(selector).bind(“event”, function() { … }); Ex.: $(“li”).bind(“click”, function() { console.log(“list item was clicked”); }); $(selector).unbind() – remove all event handlers from selected elements $(selector).on(“event1 event2..”, function() { …}); Ex.: $(“p”).on(“click”, function() { $(this).css(“background-color: red”); }); $(selector).off(“event”) $(selector).one(“event”, function) – run event only once

The jquery event object is passed to the event handling function along with this (the selected element) $(“form”).on(“submit”, function(eventObj) { // cancel default functionality for specific event (e.g. form submit) eventObj.preventDefault(); … }); properties of eventObj: pageX, pageY – mouse position type – type of event data – data can be passed to handling function when evt is bound target – DOM element that initiated the event

jQuery and css getting css properties: $(“p”).css(“background-color”) setting css properties: $(“p”).css(“font-size”, “14px”) $(“p”).css({color: “red”, width: “100%”, height: “100%”}) adding, removing, toggling css classes: css code:.fancy { border: 1px dotted #00eeff; background: url(“pic.jpg”); } jquery code: $(“#div1”).addClass(“fancy”); $(“#div1”).removeClass(“fancy”); $(“#div1”).toggleClass(“fancy”);

jQuery effects – hide/show $(selector).hide(speed,callback); $(selector).show(speed,callback); $(selector).toggle(speed,callback); where speed is “slow”, “fast” or miliseconds and callback is a function called after the effect is done; toggle() toggles between hide() and show() Ex.: $("button").click(function(){ $(“p”).hide(20); $(“p#id1”).show(“slow”); }); $("button").click(function(){ $("p").toggle(); });

jQuery effects - fading $(selector).fadeIn(speed,callback); $(selector).fadeOut(speed,callback); $(selector).fadeToggle(speed,callback); $(selector).fadeTo(speed,opacity,callback); where speed is “slow”, “fast” or miliseconds and callback is a function called after the effect is done; fadeTo() fades to an opacity Ex.: $(“button”).click(function() { $(“#div1”).fadeIn(“2000”); });

jQuery effects - sliding $(selector).slideUp(speed,callback); $(selector).slideDown(speed,callback); $(selector).slideToggle(speed,callback); where speed is “slow”, “fast” or miliseconds and callback is a function called after the effect is done; Ex.: $(“button”).click(function() { $(“#div1”).slideUp(“2000”); });

jQuery effects - animations $(selector).animate({params},speed,callback); where speed is “slow”, “fast” or miliseconds and callback is a function called after the effect is done; Ex.: $(“button”).click(function() { $(“#div1").animate({left:’100px’, top: ’75px’}); }); $(“button”).click(function() { $(“#div1”).animate({ left: ‘500px’, opacity: ‘0.3’, height: ‘100px’, width: ’60px’ });

Getting/setting html content text() - sets or returns the text content of selected elements console.log($(“p”).text()); $(“p”).text(“Test..”); html() - sets or returns the content of selected elements (including HTML markup) console.log($(“div”).html()); $(“div”).html(“ Test ”); val() - sets or returns the value of form fields attr() – get or set attribute values console.log($(“a#id1”).attr(“href”)); $(“a#id1”).attr(“href”, “

Adding/removing html content $("p").append("Some appended text."); $("p").prepend("Some appended text."); $("p").after(“ test "); $("p").before(“ test "); $("p").remove(); $("p").empty();