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.

Slides:



Advertisements
Similar presentations
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,
Advertisements

CT-376 jQuery Most popular javascript library today Latest version:
JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
JQuery A Javascript Library Hard things made eas(ier) Norman White.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
The Web Warrior Guide to Web Design Technologies
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.
Fundamentals, DOM, Events, AJAX, UI Doncho Minkov Telerik Corporation
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.
JavaScript & jQuery the missing manual Chapter 11
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.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
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.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Jquery Nasrullah. Jquery jQuery is a JavaScript Library. jQuery greatly simplifies JavaScript programming. jQuery is easy to learn.
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.
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
. 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
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.
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.
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.
Understanding JavaScript and Coding Essentials Lesson 8.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
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.
JQuery “write less, do more”. jQuery - Introduction Simply a JavaScript library to simplify JavaScript programming itself Wraps long standard JavaScript.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JQUERY AND AJAX
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
XML DOM Week 11 Web site:
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)
.. WHAT IS JQUERY JQuery is a fast, small, and feature-rich JavaScript library. Simplifies the interaction between HTML and JavaScript. The jQuery library.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
JQuery.
What is jQuery?.
Programming Web Pages with JavaScript
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
-By Yogita Nirmal.
Tek Raj Chhetri Code for Humans not for machine.
Intro to JavaScript CS 1150 Spring 2017.
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
JQuery Basics 소속 / 작성자 이 문서는 나눔글꼴로 작성되었습니다. 설치하기.
Tutorial 6 Topic: jQuery and jQuery Mobile Li Xu
JQUERY Online TRAINING AT GOLOGICA
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
Web Programming Language
..
Javascript and JQuery SRM DSC.
E-commerce Applications Development
Web Programming and Design
Presentation transcript:

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 – HTML manipulation – Event handling – Animation – Ajax Get it here: Learn more here:

$ Syntax In jQuery you will often be calling functions on jQuery objects. This selects all buttons on the current page and applies someFunction() to them. $(“button”).someFunction(); jQuery object representing one or more HTML elements Function to apply

$ Syntax Sometimes you will be calling jQuery functions that are not associated with HTML elements at all. These are called jQuery core methods. $.ajax(...) $.each(...)

Selectors Selectors “select” elements in the DOM. This is one of the best parts of jQuery – you can easily traverse the DOM and grab the element or elements that you need with CSS selectors. $(“button”) selects all button elements $(“.fancy”) selects all elements with the class fancy $(“#myElement”) selects one element with the ID myElement $(“nav.fancy”) selects all elements with the class fancy that are inside a nav element Learn more here: core/selecting-elements/ core/selecting-elements/ And here:

Selectors – More Efficient It's actually faster to use the jQuery find() function: $(“nav.fancy”) $(“nav”).find(“.fancy”) And while you can use pseudo classes, it's faster to use the jQuery functions: $(“li:first”) $(“li”).first()

Selectors – More Efficient More options with Filter... Select elements with both class1 and class2 $(“.class1.class2”) $(“.class1”).filter(“.class2”)

Selectors You can also step forward and back $(“li”).first() $(“li”).first().next() $(“li”).last().prev() Walk up the DOM tree $(“li”).parent() Walk down the DOM tree $(“ul”).children(“.someClass”)

Selectors - Closest Just because you can use parent() doesn't mean you always should! //Finds a specific element $(“span”).parent().parent(); This code is easier to read: //Finds the nearest ancestor //li element $(“span”).closest(“li”);

Change Text Let's say you want to dynamically change the text in an h1 tag: $(“h1”).text(“Hello!”); Or maybe you just want to grab the text to do something with it later: var text = $(“h1”).text();

Document Ready If you just write your JavaScript or jQuery in a script tag without wrapping it in any functions, it will execute as soon as the browser reads it. But that would be before the DOM has finished loading, so it won't find your HTML elements. You can execute code when the document has finished loading (not including images that may still be downloading) by using the “document ready” function: $(document).ready(function() { // Your code here. });

Adding Elements Create an element: var listItem = $(“ Some Text ”); Add an element to the DOM: $(“ul”).append(listItem); //add as last child $(“ul”).prepend(listItem); //add as first child $(“ul”).before(listItem); //add before ul $(“ul”).after(listItem); //add after ul

Adding Elements  One way: $(“ul”).append(listItem); //add as last child $(“ul”).prepend(listItem); //add as first child $(“ul”).before(listItem); //add before ul $(“ul”).after(listItem); //add after ul Another way: listItem.appendTo($(“ul”)); //add as last child listItem.prependTo($(“ul”)); //add as first child listItem.insertBefore($(“ul”)); //add before ul listItem.insertAfter($(“ul”)); //add after ul

Removing Elements Removing one or more elements is simple: $(“li”).remove()

Event Handlers Add a click event handler to all button elements: $(“button”). click(function(event) { } ); Anonymous Function

Passing Functions as Arguments If you wanted to pass arguments into the button's click function Wrong $(“button”).click(myFunction(myParam)); Right $(“button”).click(function () { myFunction(myParam); });

Event Handlers – Prevent Default Behavior You can prevent the default behavior of an event using the following: $(“button”).click(function(event) { event.preventDefault(); });

$(this) Sometimes you will want to refer to the element that the event occurred on. In many languages, including JavaScript, there is a this keyword. $(“button”).click(function(event) { $(“button”).text(“Clicked”) //WRONG this.text(“Clicked”); //WRONG $(this).text(“Clicked”); //RIGHT });

Changing CSS Classes Add or Remove a CSS class: $(“button”).addClass(“someClass”); $(“button”).removeClass(“someClass”);

HTML 5 Data HTML 5 added data attributes:... How Much? $(“button”).click(function() { var price = $(this).closest(“.product”).data(“price”); //do something with the price });

HTML 5 Data Another way to write it How Much? $(“.product”).on(“click”, “button”, function() { var price = $(this).closest(“.product”).data(“price”); //do something with the price });

Form Data To pull data out of an input box... $(“#someInput”).val(); To set data in an input box... $(“#someInput”).val(“new value”);

Show / Hide Show or hide element(s). There are optional parameters for animation available. Documentation: $(“selector”).show(); $(“selector”).hide(); Documentation: $(“selector”).slideUp(); $(“selector”).slideDown(); $(“selector”).slideToggle();

Callbacks A callback is a function that is called automatically at a later time. For example, if you make an AJAX request, it may take some time for the data to return (even if only a second). The beauty of AJAX is that it's asynchronous – in other words, code execution continues without waiting for the data to be returned. You may, however, want to execute code when the AJAX request returns. You can specify a callback function to handle this need.

AJAX var jqxhr = $.ajax( "URL_To_Service" ).done(function(data) { alert( "success" ); }).fail(function() { alert( "error" ); }).always(function() { alert( "complete" ); });