CGS 3066: Web Programming and Design Spring 2017

Slides:



Advertisements
Similar presentations
Getting Started with jQuery. 1. Introduction to jQuery 2. Selection and DOM manipulation Contents 2.
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,
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:
JQuery A Javascript Library Hard things made eas(ier) Norman White.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
Lesson 12- Unit L Programming Web Pages with JavaScript.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
CST JavaScript Validating Form Data with JavaScript.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Cascading Style Sheets CSS.  Standard defined by the W3C  CSS1 (released 1996) 50 properties  CSS2 (released 1998) 150 properties (positioning)  CSS3.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
 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.
SYST Web Technologies SYST Web Technologies Lesson 6 – Intro to JavaScript.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
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),
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.
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.
. Taught by: Muhammad Ali Baloch midahot. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between.
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
HTML Forms. Slide 2 Forms (Introduction) The purpose of input forms Organizing forms with a and Using different element types to get user input A brief.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
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.
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.
Chapter 6 Murach's JavaScript and jQuery, C6© 2012, Mike Murach & Associates, Inc.Slide 1.
CHAPTER 7 JQUERY WHAT IS JQUERY? jQuery is a script. It is written in JavaScript.
XML DOM Week 11 Web site:
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
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.
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
JQuery.
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Unit M Programming Web Pages with
CS5220 Advanced Topics in Web Programming More jQuery
Introduction to JavaScript Events
Unit M Programming Web Pages with
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
JQUERY Online TRAINING AT GOLOGICA
CS3220 Web and Internet Programming Client-Side JavaScript and jQuery
Document Object Model (DOM): Objects and Collections
Week 11 Web site: XML DOM Week 11 Web site:
Web Programming A different world! Three main languages/tools No Java
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
© 2015, Mike Murach & Associates, Inc.
..
Javascript and JQuery SRM DSC.
JavaScript and Events CS Programming Languages for Web Applications
Web Programming and Design
JavaScript and Events CS Programming Languages for Web Applications
Presentation transcript:

CGS 3066: Web Programming and Design Spring 2017 jQuery

JQuery Jquery is a JavaScript file that you include in your web pages. Lets you find elements using CSS-style selectors. A function called jQuery allows you to find one or more elements in the page. Creates an object called jQuery which holds references to those elements. $( ) is often used instead of jQuery(). Allows you to do something with the elements using jQuery methods. $(‘li.hot’) One parameter: CSS-style selector. Finds all li element with class hot

jQuery Similarities to DOM jQuery selectors perform a similar task to traditional DOM queries, but the syntax is much simpler. Can store the jQuery object in a variable, just as you can with DOM nodes. Can use jQuery methods and properties (like DOM methods and properties) to manipulate the DOM nodes that you select. jQuery object has many methods that can be used to work with the selected elements. $(‘li.hot’).addClass(‘complete’); $(‘li.hot’) is jQuery object . Is member operator ‘complete’

Key Differences from DOM It’s cross-browser, no need to write fallback code. Selecting elements is simpler (uses CSS-style syntax) Event handling is simpler Methods affect all the selected elements without the need to loop through each one Additional methods available for popular required tasks such as animation Once selection, can apply multiple methods to it.

Simple jQuery Example $(':header').addClass('headline'); $('li:lt(3)').hide().fadeIn(1500); $('li').on('click', function() { $(this).remove(); }); Methods objet fade the list items in and remove them when they are clicked on Here you can see how we use jQuery selectors and how to update those elements using the methods and properties of the jQuery object. The first line selects all of the headers <h1>--<h6> and add a value of headline to their class attributes The second line selects first three list items and does two thing, 1) hide the elements and then the element fade into view. The last three line of the script set an event listener on each of the <li> elements. When a user clicks on one, it triggers an anonymous function to remove that element from the page.

Why use jQuery Same as pure JavaScript but much simple to code. Problem with JavaScript Older browsers do not support the latest methods for selecting elements. IE does not treat whitespace between elements as text nodes, while other browsers do. Uses a language familiar to front-end web developers: CSS selectors Much faster at selecting elements Can be much more accurate about which elements to select Lot less code than DOM Widely used

Common tasks for jQuery Methods that allows simple way to do common task Loop through elements Add/remove elements from the DOM tree. Handle events Fade elements into/out of view Handle Ajax requests

Finding Elements Elements are selected using CSS-style selectors, also offer extra selectors Basic Selectors * All elements Element All elements with that element name #id elements whose id attribute has the value specified .class elements whose class attribute has the value specified Selector1,selector2 Elements that match more than one selector Hierarchy Ancestor descendant An elements that is a descendant of another element (e.g. li) Parent > child An element that is a direct child of another element Previous+next Adjacent sibling selector only selects elements that are immediately follow by previous element Previous-siblings Sibling selector will select any elements that are a sibling of the previous elements

Finding Elements cont…. Basic Filters :not(selector) All elements except the one in the selector (e.g., div:not(‘#summary’)) :first jQ The first element from the selection :last jQ The last element from the selection :even jQ element with an even index number from the selection :odd jQ element with an odd index number from the selection :eq(index) jQ element with index # equal to one in the paramenter :gt(index) jQ element with index # greater to one in the paramenter :header jQ All <h1>--<h6> elements :animated jQ Elements that are currently being animated :focus jQ The elements that currently has focus

Cont.. Content filters : contains(‘text’) elements with specified text as a paramenter :empty elements that has no children :parents jQ elements that has children nodes Has(selector) jQ elements that contain at least one element that matches the selector (e.g., div:has(p)) Visibility Filters :hidden jQ all elements that are hidden :visible jQ all elements that consume space in the layout of the page (not selected if displayed:none/width:0) Child filters :nth-child(expr) not a zero based eg. ul li:nth-child(2) :first-child first child Last-child: last child Only-child: only child (eg div p:onlychild)

Attributes filters and form [attribute] Elements that carry the specified attribute [attribute=‘value’] elements that carry the specified attribute with the specified value != (jQ not carry that attribute), ^= (begin with), *= (value apper somewhere), |= (equal to given string or starting with string and followed by a hyphen), ~= (value should be one of the value) Form (jQ) :input, :text, :password, :radio, :checkbox, :submit, :image, :reset, :button, :file, :selected, :enabled (all enabled form elements), :disabled (all disabled form elements), :checked (all checked radio buttons or checkboxes)

Example basic.js & get.js Single selector $(function() { var $listHTML = $('ul').html(); $('ul').append($listHTML);}); Multiple selector $(':header').addClass('headline'); $('li:lt(3)').hide().fadeIn(1500); $('li').on('click', function() { $(this).remove(); }); Get and Set Data Get information $(‘li’) If a jQuery selection holds more than one elements, if the method is used which get information form selected information then it will receive from only one element, .each() method can be used to get all elements Var content = $(‘li’).html(); // only from the first element of the list item Set Elements $(‘li’).html(‘Updated’); //updates all elements

Looping.js $(‘li em’).addClass(‘seasonal’); $(‘li.hot’).addClass(‘favorite’);

chaining.js .hide() .delay(500) $('li[id!="one"]') .hide() .delay(500) .fadeIn(1400); // semi-colon indicates end of chaining - can be writen on separate lines

including.js .ready(function() { $('h2') .hide() .slideDown(); $('li') $(document) .ready(function() {   $('h2')         .hide()         .slideDown();   $('li')         .each( function(index) {          $(this)         .delay(700*index)         .fadeIn(700);   }); });