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

Slides:



Advertisements
Similar presentations
JavaScript – Quiz #8 Lecture Code:
Advertisements

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
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,
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:
The Document Object Model (DOM) 1 JavaScript is an object-based language—that is, it’s based on manipulating objects by changing each object’s properties.
JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
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:
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.
JQuery & SharePoint San Antonio Users Group – September Meeting September 22, 2009 Microsoft SharePoint Server.
Introduction to jQuery Giuseppe Attardi Università di Pisa Some slides from: BreadFish.
JQuery The Way to JavaScript and Rich Internet Applications.
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.
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)
JQuery CS 268. What is jQuery? From their web site:
Getting Started.  jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions.
M. Taimoor Khan Courtesy: Norman White.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
JavaScript, jQuery & AJAX. What is JavaScript? An interpreted programming language with object oriented capabilities. Not Java! –Originally called LiveScript,
What is jQuery?  JavaScript Library  Functionality  DOM scripting & event handling  Ajax  User interface effects  Form validation 2.
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.
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
JQUERY | INTRODUCTION. jQuery  Open source JavaScript library  Simplifies the interactions between  HTML document, or the Document Object Model (DOM),
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
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.
JQuery Youn-Hee Han
CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
Dimiter Kunchev.  JavaScript library written by Sam Stephenson   Adds object oriented techniques  Provides.
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.
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.
Unit 13 –JQuery Basics Instructor: Brent Presley.
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.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
DOM & Jquery Nov. 09, Jquery JavaScript Library DOM (Document Object Model) HTML/XML/etc. Ajax (Asynchronous JavaScript and XML)
David Tarrant Electronics and Computer Science.
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.
.. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between HTML and JavaScript. The jQuery library.
Martin Kruliš by Martin Kruliš (v1.1)1.
JQuery Element & Attribute Selectors, Events, HTML Manipulation, & CSS Manipulation.
CS7026 jQuery Effects.
Tek Raj Chhetri Code for Humans not for machine.
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
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
HTML Level II (CyberAdvantage)
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
Introduction to jQuery
E-commerce Applications Development
Web Programming Language
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Diego Guidi - DotNetMarche

DOM tree is clunky to use No multiple handlers per event No high-level functions Browser incompatibilities = jQuery to the resque!

John Resig jQuery 1.0 out (Aug 2006) jQuery latest Production 19k – Debug 120k Cross-browser Visual Studio 2008 support

var fieldsets = document.getElementsByTagName('fieldset'); var legend, fieldset; for (var i = 0; i < fieldsets.length; i++) { fieldset = fieldsets[i]; if (!hasClass(fieldset, 'collapsible')) continue; legend = fieldset.getElementsByTagName('legend'); if (legend.length == 0) continue; legend = legend[0];... // Do your job }

$('fieldset.collapsible legend').each(function() {... // Do your job }); $("table tr:nth-child(odd)").addClass("striped");

Separate behavior from structure and style HTML => structure CSS => style JS => behavior

<button type="button" onclick="alert('behavior!');"> MyBehavior

window.onload = function() { document. getElementById('mybutton'). onclick = behavior; }; function behavior() { alert('behavior!'); }

$(document).ready(function() { $("#mybutton"). bind('click', function(ev) { alert('behavior!'); }); document.ready != pageLoad and-pageload-are-not-the-same

Supports most CSS 1-3 selectors Select all elements: $('*') Select all div elements: $('div') Select element by id: $('#id') Select all elements with class: $('.class') Combined: $('div#id.class')

Ancestor Descendant Selectors Select all paragraphs inside and element: $('#id p') Select all input elements on a form: $('form input') Parent Child Selectors Find all paragraphs elements of an element: $('#id > p') Filtering elements based on values of their attributes Find input with name attribute = value: $('input[name=??]') Find anchor tags that start with mailto: $('a[href^=mailto]') Find anchor tags that end with 'pdf': $('a[href$=pdf]')

Convenience pseudo-selectors :first:last :even:odd :hidden:visible :has:contains :enabled :disabled :animated:selected :not $('div p:not(:hidden)') Even more!

Fun with attributes get attribute values: $("#foo").attr("myattr") set attribute values: $("#foo").attr("myattr", "newval|myfunc") Fun with styling check if class name is defined: $("#foo").hasClass("myclass") add/remove class names: $("#foo").addClass("class1 class2") toggle class names: $("#foo").toggleClass("class1 class2") get/set css properties: $("#foo").css("width", "newval|myfunc") Fun with form elements get a value: $("[name=radioGroup]:checked").val()

$("#mydiv").html(" Hello, world! "); $("p").append(" Hello "); $("p").prepend(" Hello "); $(" Hi there! ").insertBefore("#mydiv"); $(" Hi there! ").insertAfter("#mydiv "); $("p").wrap(" "); $("p").empty() $("p").clone() - $("p").clone(true)

Unified method for establishing event handlers Multiple handlers for each event type on each element $("#mydiv").bind("eventName", data, listener) $("#mydiv").unbind("eventName") $("#mydiv").one("eventName", data, listener) $("#mydiv").trigger("eventName") Standard event-type names (click, mouseover…) $("#mydiv").click(function(ev) {... }) $("#mydiv").click() Namespaced events $("#mydiv").bind("click", f1).bind("click.edit", f2) $("#mydiv").unbind("click.edit")

A simpler way to animate your page $("div").hide/show() $("div").toggle() More difficult… $("div").show("slow", function() {... }) Could I try to… $("div").fadeIn/fadeOut/fadeTo $("div").slideDown/slideUp/slideToggle I need more! $("div").animate(properties, duration, easing, callback)

Utility functions $.browser $.trim(string) $.getScript(url, callback) Iterators and filters $.each(array|object, function(index|key, value) {... }) $.grep(array, function() { //... return true|false; }) var result = $.grep(array, 'a>100'); Extending objects $.extend(target,source1,source2,... sourceN) var result = $.extend({ }, { a: 1}, { b: 2}, { c: 3}. {d: 4} );

$("form input").disable(); $.fn.disable = function() { // this => wrapped-set return this.each(function() { // this => wrapped-set element if (typeof this.disabled != "undefined") this.disabled = true; }); } $("#address input").readOnly(true); $.fn.readOnly = function(readonly) { return this.filter("input:text").attr("readonly", readonly).css("opacity", readonly ? 0.5 : 1.0); }

Fetch content $("div").load(url, parameters, callback) $("mydiv").load("/url.ashx", {val: 1}, myfunc) $("mydiv").load("/url.ashx?val=1", myfunc) Get & Post $.get(url, parameters, callback) $.post(url, parameters, callback) $.getJSON(url, parameters, callback) $.getJSON("/url.ashx", {val: 1}, function(data) { alert(data); }) Ajax events ajaxStart ajaxStop ajaxSend ajaxComplete ajaxSuccessajaxError

$(' ').hide().ajaxStart(function() { $(this).show(); }).ajaxStop(function() { $(this).hide(); }).appendTo("#container"); $(" I'm foo! I'm not ").filter(".foo").click(function() { alert("I'm foo!"); }).end().appendTo("#parent");

jQuery UI Form plugin More and more… amazing examples jQuery in action