JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,

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

Getting Started with jQuery. 1. Introduction to jQuery 2. Selection and DOM manipulation Contents 2.
JavaScript & jQuery JavaScript and jQuery introduction.
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,
The DOM tree CS The DOM tree CS380 2 Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in.
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.
Introduction to HTML5 Programming donghao. HTML5 is the New HTML Standard New Elements, Attributes. Full CSS3 Support Video and Audio 2D/3D Graphics Local.
JQuery A Javascript Library Hard things made eas(ier) Norman White.
Document Object Model (DOM) JavaScript manipulation of the DOM.
Building a Rich Internet Application with jQuery Ben Dewey twentysix New York Fill this space.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
JQuery. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing and manipulation event handling.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Getting Started.  jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
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.
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),
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
The DOM tree CS The DOM tree CS380 2 Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in.
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.
JavaScript, Fourth Edition
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
. 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
CSE 154 Lecture 20: The DoM tree.
JQuery Javascript Library. JQuery Powerful JavaScript library –Simplify common JavaScript tasks –Access parts of a page using CSS or XPath-like expressions.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
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.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
 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.
JQuery Overview Unleash the Power of jQuery SoftUni Team Technical Trainers Software University
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
1 What is JQuery. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax* interactions.
Unit 13 –JQuery Basics Instructor: Brent Presley.
Introduction to jQuery. 2 Objectives When you complete this chapter, you will be able to: Select elements using jQuery syntax Use built-in jQuery functions.
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.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
CSE 154 LECTURE 9: THE DOM TREE. The DOM tree The elements of a page are nested into a tree-like structure of objects the DOM has properties and methods.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
.. 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
12/04/12 JQuery I took these slides from the site because they were pretty good looking. Instructions for editing school and department titles: Select.
Tek Raj Chhetri Code for Humans not for machine.
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
© 2015, Mike Murach & Associates, Inc.
CGS 3066: Web Programming and Design Spring 2017
JQuery.
Cleveland Tech Consulting, LLC
Introduction to jQuery
Document Object Model (DOM): Objects and Collections
..
Javascript and JQuery SRM DSC.
That detail is only sort of important That detail is only sort of important. What is important is that you have all of these HTML elements floating.
Document Object Model.
CSc 337 Lecture 9: The DoM tree.
Chengyu Sun California State University, Los Angeles
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

jQuery CS 380: Web Programming

What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. (jQuery.com)

Why learn jQuery? Write less, do more: ◦ $("p.neat").addClass("ohmy").show("slow"); Performance Plugins It’s standard … and fun!

Example: Show/Hide Button

window.onload We cannot use the DOM before the page has been constructed. jQuery gives us a more compatibile way to do this. ◦ The DOM way ◦ The direct jQuery translation ◦ The jQuery way window.onload = function() { // do stuff with the DOM } $(document).ready(function() { // do stuff with the DOM }); $(function() { // do stuff with the DOM });

Aspects of the DOM and jQuery Identification: how do I obtain a reference to the node that I want. Traversal: how do I move around the DOM tree. Node Manipulation: how do I get or set aspects of a DOM node. Tree Manipulation: how do I change the structure of the page.

The DOM tree

Selecting groups of DOM objects namedescription getElementByIdreturns array of descendents with the given tag, such as "div" getElementsByTagNamereturns array of descendents with the given tag, such as "div" getElementsByNamereturns array of descendents with the given name attribute (mostly useful for accessing form controls) querySelectorquerySelector *returns the first element that would be matched by the given CSS selector string querySelectorAllquerySelectorAll *returns an array of all elements that would be matched by the given CSS selector string

jQuery node identification // id selector var elem = $("#myid"); // group selector var elems = $("#myid, p"); // context selector var elems = $("#myid < div p"); // complex selector var elems = $("#myid < h1.special:not(.classy)");

jQuery Selectors

jQuery / DOM comparison DOM methodjQuery equivalent getElementById("id")$("#id") getElementsByTagName("tag")$("tag") getElementsByName("somename")$("[name='somename']") querySelector("selector")$("selector") querySelectorAll("selector")$("selector")

Exercise Use jQuery selectors to identify elements with these properties in a hypothetical page: ◦ All p tags that have no children, but only if they don't have a class of ignore ◦ Any element with the text "REPLACE_ME" in it. ◦ All div tags with a child that has a class of special ◦ All heading elements (h1, h2, h3, h4, h5, h6) ◦ Every other visible li. Use the DOM API to target the #square and periodically change it's position in a random direction. Use jQuery selectors instead of the DOM API.

jQuery terminology the jQuery function refers to the global jQuery object or the $ function depending on the context a jQuery object the object returned by the jQuery function that often represents a group of elements selected elements the DOM elements that you have selected for, most likely by some CSS selector passed to the jQuery function and possibly later filtered further

The jQuery object The $ function always (even for ID selectors) returns an array-like object called a jQuery object. The jQuery object wraps the originally selected DOM objects. You can access the actual DOM object by accessing the elements of the jQuery object. // false document.getElementById("id") == $("#myid"); document.querySelectorAll("p") == $("p"); // true document.getElementById("id") == $("#myid")[0]; document.getElementById("id") == $("#myid").get(0); document.querySelectorAll("p")[0] == $("p")[0];

Using $ as a wrapper $ adds extra functionality to DOM elements passing an existing DOM object to $ will give it the jQuery upgrade // convert regular DOM objects to a jQuery object var elem = document.getElementById("myelem"); elem = $(elem); var elems = document.querySelectorAll(".special"); elems = $(elems);

DOM context identification You can use querySelectorAll() and querySelector() on any DOM object. When you do this, it simply searches from that part of the DOM tree downward. Programmatic equivalent of a CSS context selector var list = document.getElementsByTagName("ul")[0]; var specials = list.querySelectorAll('li.special');

findfind / context parameter jQuery gives two identical ways to do contextual element identification var elem = $("#myid"); // These are identical var specials = $("li.special", elem); var specials = elem.find("li.special");

Types of DOM nodes This is a paragraph of text with a link in it.

Traversing the DOM tree CS38019 complete list of DOM node properties browser incompatiblity information (IE6 sucks)browser incompatiblity information

DOM tree traversal example 20 This is a paragraph of text with a link. HTML CS380

Elements vs text nodes Q: How many children does the div above have? A: 3 ◦ an element node representing the ◦ two text nodes representing "\n\t" (before/after the paragraph) Q: How many children does the paragraph have? The a tag? 21 This is a paragraph of text with a link. HTML

jQuery traversal methods

jQuery tutorials Code Academy jquery/0?curriculum_id=4fc3018f74258b f0f#!/exercises/0 Code School: first-flight