JQuery Write less, do more…. Lecture Plan jQuery – what and why The ready function Creating Content Changing Elements Applying CSS Applying functions.

Slides:



Advertisements
Similar presentations
Getting Started with jQuery. 1. Introduction to jQuery 2. Selection and DOM manipulation Contents 2.
Advertisements

Table, List, Blocks, Inline Style
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:
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.
HTML 5 and CSS 3, Illustrated Complete Unit L: Programming Web Pages with JavaScript.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Chapter 7: Dynamic HTML and Animation JavaScript - Introductory.
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)
Definition from Wikipedia.  The Prototype JavaScript Framework  implemented as a single file of JavaScript code  named prototype.js (
JQuery CS 268. What is jQuery? From their web site:
Introduction The performance of web is getting important due to the fact that more and more services have been presented by web interfaces recently. Our.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
What is jQuery?  JavaScript Library  Functionality  DOM scripting & event handling  Ajax  User interface effects  Form validation 2.
Week 4.  Three ways to apply CSS: Inline CSS Internal style sheets ( header style information) External style sheets.
JavaScript, Fifth Edition Chapter 1 Introduction to 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),
Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014.
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.
CITS1231 Web Technologies JavaScript and Document Object Model.
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.
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.
Session: 1. © Aptech Ltd. 2Introduction to the Web / Session 1  Explain the evolution of HTML  Explain the page structure used by HTML  List the drawbacks.
Unleash the Power of jQuery Doncho Minkov Telerik Software Academy academy.telerik.com Senior Technical Trainer
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.
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
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.
Creating Dynamic Webpages
Introduction to CSS. Why CSS? CSS Provides Efficiency in Design and Updates CSS relatively easy to use Can give you more flexibility and control Faster.
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.
JQuery “write less, do more”. jQuery - Introduction Simply a JavaScript library to simplify JavaScript programming itself Wraps long standard JavaScript.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
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.
CSS Cascading Style Sheets Prepared By
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
CSCI 3100 Tutorial 5 JavaScript & Ajax Jichuan Zeng Department of Computer Science and Engineering The Chinese University of Hong.
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
HTML for JavaScript Web Applications
Introduction to CSS: Selectors
Getting Started with CSS
Programming Web Pages with JavaScript
Unit M Programming Web Pages with
Unit M Programming Web Pages with
Intro to JavaScript CS 1150 Spring 2017.
CGS 3066: Web Programming and Design Spring 2017
Introduction to Web programming
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
..
E-commerce Applications Development
Computer communications
Presentation transcript:

jQuery Write less, do more…

Lecture Plan jQuery – what and why The ready function Creating Content Changing Elements Applying CSS Applying functions Lists of useful JavaScript and jQuery functions Arrays and Objects in JavaScript

jQuery – What and Why Write less, do more jQuery is a JavaScript library It makes writing JavaScript easier It smooth out some browser incompatibilities It is one of the most successful libraries

JavaScript is unavoidable HTML and CSS and JavaScript (ECMA Script) are built into the browsers and built into the W3C specifications. They cannot be avoided. Unfortunately JavaScript has been implemented rather differently in different browsers. The programmer has to write different code for each browser (IE6, IE8, Firefox, Opera etc.) The jQuery library takes care of these differences. jQuery will be compatible with new browsers (probably)

jQuery adds functionality jQuery provides additional functions. It provides the programmer with a large number of easy to use methods. It allows you to write complex scripts in just a few lines. It demands an unusual style of programming.

Preliminaries <script src=" You can download the library from google. This means it may be your user’s cache. $(function(){alert(42)}) This is 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

Example Timetables … Timetables … // hello.js $(function(){ alert("Hello world"); }); // hello.js $(function(){ alert("Hello world"); }); The HTML page – home.html The JavaScript page – hello.js

The Anonymous Function This statement: –Creates a function. –Sends that function to the ready function. The Anonymous Function will execute when the page is ready. $( function(){ alert("Hello world"); } );

Creating Content You can create content using the $ function. You can add the content to your page using the append method. $(function(){ var msg = $(' Hello World '); $('body').append(msg); });

Creating Content and Changing it After you create a node you can change it: $(function(){ for (var i=0;i<100;i++){ var msg = $(' Hello World '); msg.css('font-size',i); $('body').append(msg); } });

Some Useful jQuery functions $ –Ready function, create elements, find elements append –The append function adds to the end of an element prepend –The prepend function adds to the beginning of an element css –The function css is used to set a css property of an element html –Change the contents

Creating structures You often need to create elements that contain other elements. France Finland

Adding another country var gb = $(' '); gb.append($(' ',{text:'Great Britain'})); gb.append($(' ',{src:'flags/gb.gif'})); $('#countries').append(gb);

Examples of use $(function(){ var elem = $(' '); elem.html('An example element'); elem.css('border','solid blue'); $('body').append(elem); })

Self Test Select the correct ready function syntax a)$()(function{alert(42)}); b)$(function()(alert(42))); c)$(function(){alert(42)}); d)function $({alert(42)}); e)function $()({alert(42)});

Self Test What is the missing word ____ in this code? a)css b)append c)html d)forfend e)$. $(document).ready(function(){ var d = $(' 42 ') d.css('color','red'); $('body').____(d); });

Self Test In the flags example each image has a grey border. Select the best way to achieve this a)Apply the css rule #countries img {border:solid grey} b)Apply the css rule #countries {border:solid grey} c)Use jQuery instructions such as gb.css('border','solid grey') d)Use jQuery instructions such as $('#countries img').css('border','solid grey')

Selecting existing items You can select items with the $ function The result is a list of items $('li').css('color','red'); –Locate all elements and make them red. $('.reference').css('background-color','red'); –Locate all elements with css class=‘reference’ $('#menu1').css('border','solid thick red'); –Locate the element with id “menu1”

Select items with items A common pattern is to select elements within a named element: table#main td –Select all td elements within the table with id main ul#nav li –Select all li elements inside the ul named nav

Selecting Existing Items You can modify the selectors $('p:first-child').css('border','solid'); –Identifies the first p in each block $('p:nth-child(1)').css('border','solid'); –Selects the first child in each block $('p:eq(1)').css('border','solid'); –This gets item 1 – the second one $('p:last').css('border','solid'); –The last one of all

Combining terms As with css you can combine terms. When one term follows another separated by a space then the second is a descendant of the first –table tr td –div#content p A > indicates a direct descendant, a child –ul.menu>liprevents nested li elements matching A comma allows an independent rule - OR

Data Structures $(function(){ var ca = { cname:"A J CUMMING", caddress:{ street:"10 Colinton Rd", town:"Edinburgh", post_code:"EH14 5DT" }, transaction:[ {whn:" ",nar:"Cash Withdrawal",amt:-100}, {whn:" ",nar:"BUS FARE",amt:-35} ] }; alert(ca.transaction[1].nar); }) What expression would give each of the following: “Edinburgh” -100 “EH14 5DT” ca.transaction[1].nar This code gives “BUS FARE”

Data Structures used to create elements We can set a whole load of properties when an element is created. In this example we set the text property and the css property. The css property is itself a complex object var d = $(' ',{text:'Hello',css:{color:'green',border:'solid'}});

More to learn You can navigate through the list You can animate items You can show, hide and toggle You can apply functions to all items in the list You can store data against elements and retrieve it. You can use ajax functions You can create other effects using add-ons

Summary jQuery – what and why The ready function Creating Content Changing Elements Applying CSS Applying functions Lists of useful JavaScript and jQuery functions Arrays and Objects in JavaScript