JQuery The Way to JavaScript and Rich Internet Applications.

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.
Cleveland C#/VB.Net User Group February 24, 2009 Marv Schwartz
JavaScript and AJAX Jonathan Foss University of Warwick
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:
JQuery A Javascript Library Hard things made eas(ier) Norman White.
Introduction to jQuery Giuseppe Attardi Università di Pisa Some slides from: BreadFish.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Building a Rich Internet Application with jQuery Ben Dewey twentysix New York Fill this space.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
The Web Warrior Guide to Web Design Technologies
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
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.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Fundamentals, DOM, Events, AJAX, UI Doncho Minkov Telerik Corporation
4.1 JavaScript Introduction
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
JQuery March 09 th,2009 Create by
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
A really fairly simple guide to: mobile browser-based application development (part 4, JQuery & DOM) Chris Greenhalgh G54UBI / Chris Greenhalgh.
Execution Environment for JavaScript " Java Script Window object represents the window in which the browser displays documents. " The Window object provides.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
JavaScript, Fourth Edition
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
CA Professional Web Site Development Class 2: Anatomy of a Web Site and Web Page & Intro to HTML.
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
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
LOGO sparcs.org 1 jQuery Tutorial Presenter ㅎㅇㅎㅇ.
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.
JQuery Overview Unleash the Power of jQuery SoftUni Team Technical Trainers Software University
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
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.
Introduction to AJAX MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/4/2016.
1/7/2016www.infocampus.co.in1. 1/7/2016www.infocampus.co.in2 Web Development training gives you and all-round training in both the design and the development.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
JQuery Element & Attribute Selectors, Events, HTML Manipulation, & CSS Manipulation.
JQuery.
Unleash the Power of jQuery
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
Document Object Model (DOM): Objects and Collections
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
Introduction to AJAX MIS 3502 Jeremy Shafer Department of MIS
Web Programming A different world! Three main languages/tools No Java
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
MIS JavaScript and API Workshop (Part 2)
Getting started with jQuery
An introduction to jQuery
E-commerce Applications Development
An introduction to jQuery
Chengyu Sun California State University, Los Angeles
An introduction to jQuery
Presentation transcript:

jQuery The Way to JavaScript and Rich Internet Applications

Introduction to jQuery Developed by John Resig at Rochester Institute of Technology Developed by John Resig at Rochester Institute of Technology “jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML. It was released in January 2006 at BarCamp NYC by John Resig.” “jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML. It was released in January 2006 at BarCamp NYC by John Resig.”JavaScript libraryJavaScriptHTMLBarCampJohn ResigJavaScript libraryJavaScriptHTMLBarCampJohn Resig “jQuery is free, open source software Dual-licensed under the MIT License and the GNU General Public License.” “jQuery is free, open source software Dual-licensed under the MIT License and the GNU General Public License.”free, open source softwareDual-licensedMIT LicenseGNU General Public Licensefree, open source softwareDual-licensedMIT LicenseGNU General Public License “It’s all about simplicity. Why should web developers be forced to write long, complex, book-length pieces of code when they want to create simple pieces of interaction?” “It’s all about simplicity. Why should web developers be forced to write long, complex, book-length pieces of code when they want to create simple pieces of interaction?” Current version is Current version is Version 1.4 due out soon. Version 1.4 due out soon.

John Resig John Resig is a JavaScript Tool Developer for the Mozilla Corporation and the author of the book Pro JavaScript Techniques. He's also the creator and lead developer of the jQuery JavaScript library. John Resig is a JavaScript Tool Developer for the Mozilla Corporation and the author of the book Pro JavaScript Techniques. He's also the creator and lead developer of the jQuery JavaScript library.Mozilla CorporationPro JavaScript TechniquesjQuery JavaScript libraryMozilla CorporationPro JavaScript TechniquesjQuery JavaScript library Currently, John is located in Boston, MA. He's hard at work on his second book, Secrets of the JavaScript Ninja, due in bookstores in Currently, John is located in Boston, MA. He's hard at work on his second book, Secrets of the JavaScript Ninja, due in bookstores in Secrets of the JavaScript Ninja Secrets of the JavaScript Ninja Microsoft and Nokia have announced plans to bundle jQuery on their platforms,[1] Microsoft adopting it initially within Visual Studio[2] for use within Microsoft's ASP.NET AJAX framework and ASP.NET MVC Framework whilst Nokia will integrate it into their Web Run-Time platform. Microsoft and Nokia have announced plans to bundle jQuery on their platforms,[1] Microsoft adopting it initially within Visual Studio[2] for use within Microsoft's ASP.NET AJAX framework and ASP.NET MVC Framework whilst Nokia will integrate it into their Web Run-Time platform. MicrosoftNokia[1]Visual Studio[2] ASP.NET AJAXASP.NET MVC Framework MicrosoftNokia[1]Visual Studio[2] ASP.NET AJAXASP.NET MVC Framework

Introduction to jQuery Why do I want it Why do I want it –Rich Internet Applications (RIA) –Dynamic HTML (DHTML) How do I get it How do I get it – How can I learn it How can I learn it –jQuery in Action by Bibeault & Katz, Manning –jQuery Visual Quickstart Guide by Holzner, Peachpit – –docs.jquery.com – – – - cheat sheet –

Plan for the 4 sessions Class I – Introduction, installation, “Howdy World”, Ready function, DOM, Selecting and Formatting web page elements Class I – Introduction, installation, “Howdy World”, Ready function, DOM, Selecting and Formatting web page elements Class II – Events and Animations Class II – Events and Animations Class III – jQuery Plugin libraries Class III – jQuery Plugin libraries Class IV – AJAX with PHP and ASP.NET Class IV – AJAX with PHP and ASP.NET

Introduction to jQuery Installation – You just download the jquery js file and put it in your website folder Installation – You just download the jquery js file and put it in your website folder –Can access via URL

What jQuery Does “Unobtrusive” JavaScript – separation of behavior from structure “Unobtrusive” JavaScript – separation of behavior from structure CSS – separation of style from structure CSS – separation of style from structure Allows adding JavaScript to your web pages Allows adding JavaScript to your web pages Advantages over just JavaScript Advantages over just JavaScript –Much easier to use –Eliminates cross-browser problems HTML to CSS to DHTML HTML to CSS to DHTML

5 Things jQuery Provides Select DOM (Document Object Model) elements on a page – one element or a group of them Select DOM (Document Object Model) elements on a page – one element or a group of them Set properties of DOM elements, in groups (“Find something, do something with it”) Set properties of DOM elements, in groups (“Find something, do something with it”) Creates, deletes, shows, hides DOM elements Creates, deletes, shows, hides DOM elements Defines event behavior on a page (click, mouse movement, dynamic styles, animations, dynamic content) Defines event behavior on a page (click, mouse movement, dynamic styles, animations, dynamic content) AJAX calls AJAX calls

The DOM Document Object Model Document Object Model jQuery is “DOM scripting” jQuery is “DOM scripting” Heirarchal structure of a web page Heirarchal structure of a web page You can add and subtract DOM elements on the fly You can add and subtract DOM elements on the fly You can change the properties and contents of DOM elements on the fly You can change the properties and contents of DOM elements on the fly

The DOM “The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Aspects of the DOM (such as its "Elements") may be addressed and manipulated within the syntax of the programming language in use.” Wikipedia “The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Aspects of the DOM (such as its "Elements") may be addressed and manipulated within the syntax of the programming language in use.” Wikipediacross-platform languageobjectsHTMLXHTMLXMLcross-platform languageobjectsHTMLXHTMLXML

The jQuery Function jQuery() = $() jQuery() = $() $(function)The “Ready” handler $(function)The “Ready” handler $(‘selector’)Element selector expression $(‘selector’)Element selector expression $(element)Specify element(s) directly $(element)Specify element(s) directly $(‘HTML’)HTML creation $(‘HTML’)HTML creation $.function()Execute a jQuery function $.function()Execute a jQuery function $.fn.myfunc(){}Create jQuery function $.fn.myfunc(){}Create jQuery function

Tutorial 1 – The Ready Function Set up a basic HTML page and add jQuery Set up a basic HTML page and add jQuery Create a “ready” function Create a “ready” function Call a function Call a function 5 ways to specify the ready function 5 ways to specify the ready function –jquery(document).ready(function(){…};); –jquery().ready(function(){…};) –jquery(function(){…};) –jquery(dofunc); –$(dofunc);

Tutorial 2 – Selecting Elements Creating a “wrapped set” $(selector) $(selector) selector: selector: –$(‘#id’)id of element –$(‘p’)tag name –$(‘.class’)CSS class –$(‘p.class’) elements having the CSS class –$(‘p:first’)$(‘p:last’)$(‘p:odd’)$(‘p:even’) –$(‘p:eq(2)’)gets the 2 nd element (1 based) –$(‘p’)[1]gets the 2 nd element (0 based) –$(‘p:nth-child(3))gets the 3 rd element of the parent. n=even, odd too. –$(‘p:nth-child(5n+1)’)gets the 1 st element after every 5th one –$(‘p a’) elements, descended from a –$(‘p a’) elements, descended from a –$(‘p>a’) elements, direct child of a –$(‘p>a’) elements, direct child of a –$(‘p+a’) elements, directly following a –$(‘p+a’) elements, directly following a –$(‘p, a’) and elements –$(‘li:has(ul)’) elements that have at least one descendent –$(‘:not(p)’)all elements but elements –$(‘p:hidden’)only elements that are hidden –$(‘p:empty’) elements that have no child elements

Selecting Elements, cont. $(‘img’[alt]) elements having an alt attribute $(‘img’[alt]) elements having an alt attribute $(‘a’[href^= elements with an href attribute starting with ‘ $(‘a’[href^= elements with an href attribute starting with ‘ $(‘a’[href$=.pdf]) elements with an href attribute ending with ‘.pdf’ $(‘a’[href$=.pdf]) elements with an href attribute ending with ‘.pdf’ $(‘a’[href*=ntpcug]) elements with an href attriute containing ‘ntpcug’ $(‘a’[href*=ntpcug]) elements with an href attriute containing ‘ntpcug’

Useful jQuery Functions.each()iterate over the set.each()iterate over the set.size()number of elements in set.size()number of elements in set.end()reverts to the previous set.end()reverts to the previous set.get(n)get just the nth element (0 based).get(n)get just the nth element (0 based).eq(n)get just the nth element (0 based) also.lt(n) &.gt(n).eq(n)get just the nth element (0 based) also.lt(n) &.gt(n).slice(n,m)gets only nth to (m-1)th elements.slice(n,m)gets only nth to (m-1)th elements.not(‘p’)don’t include ‘p’ elements in set.not(‘p’)don’t include ‘p’ elements in set.add(‘p’)add elements to set.add(‘p’)add elements to set.remove() removes all the elements from the page DOM.remove() removes all the elements from the page DOM.empty()removes the contents of all the elements.empty()removes the contents of all the elements.filter(fn/sel)selects elements where the func returns true or sel.filter(fn/sel)selects elements where the func returns true or sel.find(selector)selects elements meeting the selector criteria.find(selector)selects elements meeting the selector criteria.parent()returns the parent of each element in set.parent()returns the parent of each element in set.children()returns all the children of each element in set.children()returns all the children of each element in set.next()gets next element of each element in set.next()gets next element of each element in set.prev()gets previous element of each element in set.prev()gets previous element of each element in set.siblings()gets all the siblings of the current element.siblings()gets all the siblings of the current element

Tutorial 3 – Formatting Elements.css(property, value).css(property, value).html().html().val()(form elements).val()(form elements).text().text().addClass(‘class’).addClass(‘class’).removeClass(‘class’).removeClass(‘class’)

Tutorial 4 – Add Page Elements $(‘#target’).before(‘ Inserted before #target ’); $(‘#target’).before(‘ Inserted before #target ’); $(‘#target’).after(‘ This is added after #target ’); $(‘#target’).after(‘ This is added after #target ’); $(‘#target’).append(‘ Goes inside #target, at end ’); $(‘#target’).append(‘ Goes inside #target, at end ’); $(‘#target’).wrap(‘ ’); $(‘#target’).wrap(‘ ’);

Adding Events Mouseover events – bind, hover, toggle Mouseover events – bind, hover, toggle Button click events Button click events Keystrokes Keystrokes

Event Background DOM Level 2 Event Model DOM Level 2 Event Model –Multiple event handlers, or listeners, can be established on an element –These handlers cannot be relied upon to run an any particular order –When triggered, the event propagates from the top down (capture phase) or bottom up (bubble phase) –IE doesn’t support the “capture phase”

Basic Syntax of Event Binding $(‘img’).bind(‘click’,function(event){alert(‘Howdy’;}); $(‘img’).bind(‘click’,function(event){alert(‘Howdy’;}); $(‘img’).bind(‘click’,imgclick(event)); $(‘img’).bind(‘click’,imgclick(event)); –Allows unbinding the function $(‘img’).unbind(‘click’,imgclick()); $(‘img’).unbind(‘click’,imgclick()); $(‘img’).unbind(‘click’); $(‘img’).unbind(‘click’); $(‘img’).one(‘click’,imgclick(event)); $(‘img’).one(‘click’,imgclick(event)); –Only works once $(‘img’).click(imgclick); $(‘img’).click(imgclick); $(‘img’).toggle(click1, click2); $(‘img’).toggle(click1, click2); $(‘img’).hover(mouseover, mouseout); $(‘img’).hover(mouseover, mouseout);

Element Properties – “this” this this this.id this.id this.tagName this.tagName this.attr this.attr this.src this.src this.classname this.classname this.title this.title this.alt this.alt this.value(for form elements) this.value(for form elements)

‘Event’ properties event.targetref to element triggering event event.targetref to element triggering event Event.target.idid of element triggering event Event.target.idid of element triggering event event.currentTarget event.currentTarget event.typetype of event triggered event.typetype of event triggered event.datasecond parm in the bind() func event.datasecond parm in the bind() func Various mouse coordinate properties Various mouse coordinate properties Various keystroke related properties Various keystroke related properties

Event Methods.stopPropagation()no bubbling.stopPropagation()no bubbling.preventDefault()no link, no submit.preventDefault()no link, no submit.trigger(eventType)does not actually trigger the event, but calls the appropriate function specified as the one tied to the eventType.trigger(eventType)does not actually trigger the event, but calls the appropriate function specified as the one tied to the eventType.click(), blur(), focus(), select(), submit().click(), blur(), focus(), select(), submit() –With no parameter, invokes the event handlers, like trigger does, for all the elements in the wrapped set

Shortcut Event Binding.click(func).click(func).submit(func).submit(func).dblclick(func).dblclick(func).mouseover(func).mouseover(func).mouseout(func).mouseout(func).select(func).select(func)

Useful Event Functions.hide()display:true.hide()display:true.show()display:none.show()display:none.toggle(func1, func2) first click calls func1, next click executes func2.toggle(func1, func2) first click calls func1, next click executes func2.hover(over, out)mouseover, mouseout.hover(over, out)mouseover, mouseout

AJAX What is AJAX What is AJAX The basic AJAX function – XMLHttpRequest The basic AJAX function – XMLHttpRequest Initiating a request Initiating a request Getting the response Getting the response