JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.

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

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.
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.
School of Computing and Information Systems CS 371 Web Application Programming jQuery.
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
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
JQUERY – UI & THEMES "WRITE LESS, DO MORE" Built in interface elements.
CST JavaScript Validating Form Data with JavaScript.
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.
Nguyen Ich Cuong.  Course duration: 45’  Purpose: Present Introduction to JQuery  Targeted attendees: NICorp Trainee  Tests/quiz: Yes - 10’
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.
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 | 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.
JQuery Write less, do more…. Lecture Plan jQuery – what and why The ready function Creating Content Changing Elements Applying CSS Applying functions.
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.
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.
CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
Introduction to jQuery. jQuery Quick facts Is a cross-compatible JavaScript library Released in 2006 by John Resig Simplifies HTML document traversing,
JQuery Javascript Library. JQuery Powerful JavaScript library –Simplify common JavaScript tasks –Access parts of a page using CSS or XPath-like expressions.
Cs332a_chapt10.ppt CS332A Advanced HTML Programming DHTML Dynamic Hypertext Markup Language A term describing a series of technologies Not a stand-a-lone.
JQuery Introduction © Copyright 2014, Fred McClurg All Rights Reserved.
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.
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.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
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.
05 | Integrating JavaScript and MVC 4 Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek.
JQuery Animation. If you look at example1.html, you will see that it is a basic web page with links to the jquery library, and a script.js file and some.
Week 3: Introduction to jQuery and Adv. Javascript.
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,
JavaScript, Sixth Edition
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.
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
JQUERY Online TRAINING AT GOLOGICA
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
Web Programming Language
..
SEEM4570 Tutorial 5: jQuery + jQuery Mobile
E-commerce Applications Development
Web Programming Language
Getting started with jQuery
Presentation transcript:

jQuery Adding behaviour…

Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next Ajax –Getting data from the server

Previously Write less, do more jQuery is a JavaScript library It makes writing JavaScript easier It smooth out some browser incompatibilities

Loading jQuery You can download the library from google. This means it may be your user’s cache. $(document).ready The ready function takes a function as a parameter. The function is executed when the page has loaded. This is a useful time to set up the page

The $ function to select The $ function returns a list of matching elements It uses css style matches It uses XPath style matches Key HCI Human Computer Interaction ISO Information Systems in Organisations SD Software Development in Java $(document).ready(function(){ $('#key th').css('color','red'); });

Function css The $ function returns a list of elements The css function is applied to each of these elements The css function can take an attribute and a value as shown It can also take a “map” of attribute/value pairs: $('#key th').css('color','red'); $('#key th'). css({backgroundColor:'black',color:'white'});

The $ function to create You can use $ to create nodes You can use append or prepend to add //The basic $('body').append($(' Hide key ')); //With styling $('body').prepend($(' ',{text:'Hide key', css:{color:'blue'}}));

A link to “toggle” the second table

Functions required html –This has two forms –html() returns the contents of the node as a string –html("one two three") changes the contents is –This takes a css or Xpath expression and returns true or false click –This property attaches a function that will be applied when the user clicks fadeIn and fadeOut –fadeOut makes an element disappear – it can take “fast” or “slow” or milliseconds

Add the link text We add the div, set the text, make it blue and change the cursor – all of this to encourage the user to click on it. $(document).ready( function () { $('body').prepend($(' ', {text:'Hide key', css:{color:'blue', cursor:'pointer'}, })); });

Add Behavior $('body').prepend($(' ', {text:'Hide key', css:{color:'blue’, cursor:'pointer'}, click:function(){ if ($('#key').is(':visible')){ $('#key').fadeOut('slow'); $(this).html('Show key'); }else{ $('#key').fadeIn('slow'); $(this).html('Hide key'); } }));

Add behaviour The click attribute is set to be a function The second table has id key It will be visible or not We could have used the toggle method, but the if statement allows us more control You can use show and hide You can specify no parameter (instant) or fast or slow or give the number of millseconds for the transition. this is the thing that the user clicked on.

mouseover and mouseout You can change elements on mouseover. You can use this to refer to the element you are over: Notice that only non empty items are affected $('table td:not(:empty)').mouseover(function(){ $(this).css('background','red'); }); $('table td').mouseout(function(){ $(this).css('background','inherit'); });

A more complicated example

Using filter, find and first $('table td:not(:empty)').mouseover(function(){ var module = $(this).find('div').first().html(); var l = $('td:not(:empty)').filter(function(){ return $(this).find('div').first().html()==module; }); l.css('background','red'); }); $('table td').mouseout(function(){ $('table td').css('background','inherit'); });

filter Applied to a list of elements Takes a function that returns true or false The function can use the index or the object this It returns only those elements that pass the test

find find is applied to a list of elements You can include css or XPath strings It searches the descendants of the element and returns those that match The function parents does the same thing for ancestors first The function first returns only the first element from the list The function last does something similar You can include a css or XPath string as a condition

Show and Hide You can show or hide an element from a click event (or similar) I agree to the terms and conditions Show the terms and conditions Yada yada. I agree to the terms and conditions Show the terms and conditions Yada yada. $(function(){ $('#whatarethey').click(function(){ $('#terms').show(); }); $(function(){ $('#whatarethey').click(function(){ $('#terms').show(); }); #terms{ display:none; } #whatarethey{ cursor:pointer; } #terms{ display:none; } #whatarethey{ cursor:pointer; }

Show, hide, toggle, fadeIn, fadeOut You can also use toggle() You can give the show/hide the speed –“fast”, “slow”, 500 There are other effects that you can use: –fadeIn/fadeOut –slideUp/slideDown You can use jQuery UI to get far too many more

Animation You can animate items $('#d1').click(function(){ $(this).animate({'margin-left':500}); }); $('#d2').click(function(){ $(this).animate({'width':'20ex'}); }); $('#d3').click(function(){ $(this).animate({'margin-left':'20ex'}, 3000,function(){ $(this).animate({'margin-left':'0ex'}); });

toggleClass Often it is best to use a css class to provide a level of indirection If you want to allow the user to select an item or several items then the following pattern works well: $('li').click(function(){ $(this).toggleClass('hi'); }) $('li').click(function(){ $('.hi').removeClass('hi'); $(this).addClass('hi'); })

Multiple Choice – Choose One

Summary You can attach a function to an action: –$(‘#target’).click(function(){alert(“You clicked!”);}) –$(‘div’).mouseover(function(){$(this).css{‘color’,’red’)}}); The functions are anonymous this refers to the item that has been clicked, usually you need to use $(this) Traversal – you can get to related nodes using find, filter, parent...