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.

Slides:



Advertisements
Similar presentations
17 HTML, Scripting, and Interactivity Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and.
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 A Javascript Library Hard things made eas(ier) Norman White.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
The Web Warrior Guide to Web Design Technologies
Introducing Cascading Style Sheets  Cascading Style Sheet Basics  Creating Styles  Using Styles  Manipulating Styles  Text Formatting with CSS.
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Computer Science 103 Chapter 4 Advanced JavaScript.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
JQuery CS 268. What is jQuery? From their web site:
JavaScript & jQuery the missing manual Chapter 11
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
KRAD makes it easy to handle HTML events in your webpage. Kuali University: Apply Now Lab 6: Fun with HTML Events Lab Objectives HTML Events – what are.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Using Styles and Style Sheets for Design
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Chapter 19: Adding JavaScript
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
XP Dreamweaver 8.0 Tutorial 3 1 Adding Text and Formatting Text with CSS Styles.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
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.
Use CSS to Implement a Reusable Design Selecting a Dreamweaver CSS Starter Layout is the easiest way to create a page with a CSS layout You can access.
Web Development 101 Presented by John Valance
INTRODUCTION TO CSS. TOPICS TO BE DISCUSSED……….  Introduction Introduction  Features of CSS Features of CSS  Creating Style Sheet Creating Style Sheet.
Introducing Cascading Style Sheets. Cascading Style Sheet Basics  Cascading Style Sheet Basics  Creating Styles  Using Styles  Manipulating Styles.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
Tutorial 3 Adding and Formatting Text with CSS Styles.
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.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
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.
CHAPTER 7 JQUERY WHAT IS JQUERY? jQuery is a script. It is written in JavaScript.
Chapter 10 Dynamic HTML (DHTML) JavaScript, Third Edition.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
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)
JQuery.
Using DHTML to Enhance Web Pages
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
Introduction to Web programming
Section 17.1 Section 17.2 Add an audio file using HTML
JavaScript Functions.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
JavaScript and Events.
JavaScript Introduction
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
JQuery with ASP.NET.
E-commerce Applications Development
Chengyu Sun California State University, Los Angeles
CS7026 jQuery Events.
Web Programming and Design
Presentation transcript:

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 role as a contributor to HTML5’s adoption: It makes common and complex JavaScript tasks much easier to implement.  By simplifying large portions of code into two or three lines, jQuery automates some of the little tricks and quirks required to execute complex tasks across most common web browsers.

Loading jQuery  To use jQuery, you can either download and install the JavaScript library or use a link to a hosted copy.  Download the latest version of jQuery from the jQuery Project, and save the library alongside your HTML files on your web server.

jQuery Library  jQuery is fairly specific about when and how its functionality can be executed.  jQuery provides a global function with a dollar sign.  This is automatically used as a shortcut to provide easy access to the jQuery() global function.  Before you can execute any jQuery function or method, one of two things must happen in each web page:  Your jQuery code must be defined after all HTML code that it will manage, or you must delay the execution of your jQuery code until after the document has finished loading.

jQuery Library  The latter is preferred because this makes the placement of your code independent of the HTML.  The document-ready method calls a function when the document is finished loading; therefore, all your jQuery- specific code runs inside of this handler function:  Because this document-ready code is rather long and very common, you can use a shortcut:

Select HTML Elements  jQuery is designed to let you select the HTML element or elements that you are interested in and then execute a method on them to manipulate them.  The selection process uses a syntax very similar to CSS.

CSS-Style Selectors  jQuery uses selectors that closely follow CSS.  The method that follows will be applied to all matching HTML elements.

Object Selectors  Some methods require that you select the entire document or window object in order to proceed.  You can do so by specifying the object variable in the selector function and then calling your method.  The $(this) object selector is unique as it is only applicable inside a function handle of another method.  Effectively, $(this) is a shortcut to the parent object that triggered the original selector match.

Applying jQuery Methods  After you have a $(selector) established, you can begin calling jQuery methods.  jQuery has methods that enable you to manipulate the DOM of all HTML elements that match $(selector).  For example, you can add a CSS class, manipulate HTML element attributes, change entire HTML blocks, and even make an HTML block dynamically disappear with an animation:

Chaining Methods  Most jQuery methods actually return a jQuery object of the same type as the original $(selector).  This means that you can chain multiple methods together in a single command with a single selector:  For example, all input check boxes are selected, and a background-color: red CSS declaration is applied to them.  Then, of those that were modified, find() filters out the ones that are checked from the initial selector, allowing css() to set color: green only to them.

Load jQuery  Add a tag to load jquery-version.js into your HTML.

Execute jQuery Methods on Elements  After jQuery is loaded, you can execute any jQuery methods using the following syntax within a tag group:

Execute jQuery Methods on Elements  You can shorten the $(document).ready() wrapper to something a little easier to remember:

Manipulate HTML Elements  You can manipulate and change HTML elements with jQuery.  This enables you to dynamically change the original HTML tags and attributes rendered in the web browser after the web page actually loads.  The HTML content within selected elements can be modified using the html() method.  Or you can inject new HTML content before HTML elements using before() and after using after().  In all three cases, you can specify the new HTML code as a parameter to the method.

Manipulate HTML Elements  You can also edit the selected HTML elements by adding or changing individual attributes.  Use attr() to get or set values or removeAttr() to remove an attribute.  Finally, you can remove selected HTML elements using detach().  This will purge the selected element and all its descendents from your web page.  A complete list of all manipulation methods provided by the jQuery API can be found at the jQuery API Reference page at

Manipulate HTML Elements

Customize Browser Events with jQuery  One of jQuery’s strengths is its capability to modify browser activity based on what event you are interested in.  There are three components required when customizing a browser event in jQuery:  What is the object, what will the user do to that object, and what process occurs when the user does it.  The first component is easy; that is the standard $(selector) you have used earlier.

Customize Browser Events with jQuery  The second component is the event method itself. Here are some of the most common browser events you can customize:  click(), dblclick() — When the user clicks or double-clicks an object.  hover() — When the user hovers over an object. Note that this event takes two handler functions, representing when the user hovers in and hovers out.  focus(), blur() — When the user selects and deselects a form element.  submit() — When the user submits a form.  keypress() — When the user presses a key.  keydown(), keyup() — Divides a keypress event into separate key-down and key-up events.

Customize Browser Events with jQuery  The third component is the handler function within which an event object needs to be retrieved: function(event){... }.  This helps you identify additional specifics about the event itself.  A full list of jQuery API events, including the low-level bind() method that provides the most flexibility, can be found at

Customize Browser Events with jQuery

Hide and Show Content with jQuery  You can add special effects to your web page with jQuery, the simplest being hide() and show(), with an optional duration parameter that produces a transition effect to dynamically make the content disappear and reappear in the browser.  These effects, along with animate(), fade(), and slide(), launch when the user triggers an event such as a button click, mouse hover, or a keypress.  So, to tie the display of one element to the event of another, you will need to first customize the browser event on the first event selector and then in the event handler function call the effect method on a target selector, or what you want to manipulate.

Hide and Show Content with jQuery  For example, you can easily control the display of a... block by creating two span tags and registering a click event handler on them:

Hide and Show Content with jQuery

 Use the CSS rule for the fake-link class

Hide and Show Content with jQuery

 The click() event can be tied to any HTML object, such as a paragraph, image, or table. Furthermore, any type of event can be used to trigger the effect, such as dblclick(), hover(), or even a specific keyboard letter.

Add and Remove CSS Classes on Elements with jQuery  It is possible for you to dynamically add or remove CSS styles on elements through established class names.  This is done by manipulating the class attribute on selected elements.  There are four jQuery methods that you can use to manipulate an element’s class:

Add and Remove CSS Classes on Elements with jQuery  addClass() simply adds classname into all elements that match selector, and removeClass() removes classname.  The hasClass() method returns a Boolean that is true if classname is currently a member of selector elements; otherwise, it returns false.  The toggleClass() method actually combines all three CSS methods into one: It checks if classname is present, adds classname if missing, and removes it if present.

Add and Remove CSS Classes on Elements with jQuery

Send Custom HTML Attribute Data into jQuery  You may have a requirement that an element link needs to send additional data to JavaScript, beyond the typical id and class attribute selectors and standard element attributes.  Such is the case if you have multiple objects, each registered to the same browser click event handler function, but additional “parameters” need to be passed into that handler function.  This can be done by specifying arbitrary data-* attributes in your HTML elements, which are user-defined attributes exempt from HTML5 validation checking.  In the jQuery handler function that receives the event, you can retrieve the attribute’s value with $(this).attr(‘data-*’).

Send Custom HTML Attribute Data into jQuery  Imagine a series of buttons that all run the same JavaScript function run_program(), but each button runs the function with a different parameter.  You can create the series of buttons with the same class and then set the data-var attribute to the unique value for each button:

Send Custom HTML Attribute Data into jQuery  jQuery can register a click event on the button.run-program selector, allowing you to monitor all four buttons at once.  When the user clicks one, retrieve the custom attribute value within the function handler with

Send Custom HTML Attribute Data into jQuery