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.

Slides:



Advertisements
Similar presentations
By ishaq shinwari.  jQuery is a lightweight, "write less, do more", JavaScript library.  The purpose of jQuery is to make it much easier to use JavaScript.
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,
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Events Part III The event object. Learning Objectives By the end of this lecture, you should be able to: – Learn to use the hover() function – Work with.
Event Handling. Overview How to listen (and not listen) for events Creating a utility library (and why you should) Typology of events Pairing event listeners.
JavaScript (Part 2) CS 183 4/13/2010. JavaScript (Part 2) Will cover: ◦ For.. In ◦ Events ◦ Try.. Catch, Throw ◦ Objects.
Tutorial 15 Working with the Event Model. XP Objectives Compare the IE and W3C event models Study how events propagate under both event models Write a.
20-Jun-15 JavaScript and HTML Simple Event Handling.
JavaScript 101 Lesson 5: Introduction to Events. Lesson Topics Event driven programming Events and event handlers The onClick event handler for hyperlinks.
Technology Education and Information Design Copyright 2009 MediTech NUI: New User Interface Online Training.
XP Tutorial 8 New Perspectives on JavaScript, Comprehensive1 Working with the Event Model Creating a Drag-and-Drop Shopping Cart.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
JS: DOM Form Form Object Form Object –The Form object represents an HTML form. –For each instance of a tag in an HTML document, a Form object is created.
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.
JQuery March 09 th,2009 Create by
Event Handlers CS101 Introduction to Computing. Learning Goals Learn about event handlers Determine how events are useful in JavaScript Discover where.
Lecture Set 13 Drawing Mouse and Keyboard Events Part B – Mouse and Keyboard Events.
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.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CO1552 Web Application Development HTML Forms, Events and an introduction to JavaScript.
DOM Events. JS Events Outline About Events – Introduction – Registering events – Getting information from events Event order/phases – Preventing default.
Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.
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.
Events Part II Browser Variations Document / Window Events Form Events --- Using named functions (instead of anonymous)
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
Project 8: Reacting to Events Essentials for Design JavaScript Level One Michael Brooks.
MIS333k(Poynor) Chapter 2. Intro to VBA Events Where to plug in your programs?
7. JavaScript Events. 2 Motto: Do you think I can listen all day to such stuff? –Lewis Carroll.
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
Document Object Model Nasrullah. DOM When a page is loaded,browser creates a Document Object Model of the Page.
LESSON : EVENTS AND FORM VALIDATION -JAVASCRIPT. EVENTS CLICK.
 objects in Client  What is Event?  Event Handlers  programming.
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.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
CHAPTER 7 JQUERY WHAT IS JQUERY? jQuery is a script. It is written in 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.
Implement User Input Windows Development Fundamentals LESSON 2.4A.
Selectors & Events. What do Selectors do? What do Selectors do? Selectors allow you to manipulate DOM elements as a group or as a single node. This allows.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
CSE 154 LECTURE 10: MORE EVENTS. Problems with reading/changing styles Click Me HTML window.onload = function() { document.getElementById("clickme").onclick.
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.
JQuery.
JavaScript and HTML Simple Event Handling 11-May-18.
Introduction to JavaScript Events
Introduction to Web programming
JavaScript and Events.
JavaScript and HTML Simple Event Handling 19-Sep-18.
CSE 154 Lecture 11: More Events.
Working with the Event Model
Events.
Introduction to jQuery
Web Programming Language
Lecture 11: Keyboard Events
E-commerce Applications Development
JavaScript and Events CS Programming Languages for Web Applications
CS7026 jQuery Events.
Lecture 11: Keyboard Events
CHAPTER 6 EVENTS. CHAPTER 6 EVENTS WHAT IS AN EVENT?
SEEM4540 Tutorial 3 jQuery Wong Wai Chung.
JavaScript and HTML Simple Event Handling 26-Aug-19.
JavaScript and Events CS Programming Languages for Web Applications
JavaScript and HTML Simple Event Handling 4-Oct-19.
JQuery.
Presentation transcript:

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 Web Application. E.g.  A mouse click  A web page loading  A mouse rolling over an element  Submitting an HTML form  A keystroke on your keyboard  When these events are fired you can then respond to them with a custom function to do pretty much whatever you want.  The term "fires" is often used with events. E.g.: "The keypress event fires the moment you press a key".

Common DOM Events  Mouse Events:  click  dblclick  mouseenter  mouseleave  hover  Keyboard Events  keypress  keydown  keyup

Common DOM Events  Form Events  Submit  Change  Focus  Blur  Document.Window Events  load  resize  scroll  unload

jQuery Syntax For Event Methods  In jQuery, most DOM events have an equivalent jQuery method.  To assign a click event to all paragraphs on a page, you can do this: $("p").click();  The next step is to define what should happen when the event fires. You must pass a function to the event: $("p").click(function(){ // action goes here!! });

Some Common Event Methods…  $(document).ready()  The $(document).ready() method allows us to execute a function when the document is fully loaded.  click()  The click() method attaches an event handler function to an HTML element.  The function is executed when the user clicks on the HTML element.  The following example says: When a click event fires on a element; hide the current element: $("p").click(function(){ $(this).hide(); });

Some Common Event Methods…  dblclick()  Executed when the user double-clicks on the HTML element:  mouseenter()  Executed when the mouse pointer enters the HTML element:  $("#p1").mouseenter(function(){ alert("You entered p1!"); });  mouseleave()  Executed when the mouse pointer leaves the HTML element:

Some Common Event Methods…  hover()  The hover() method takes two functions and is a combination of the mouseenter() and mouseleave() methods.  The first function is executed when the mouse enters the HTML element, and the second function is executed when the mouse leaves the HTML element:  $("#p1").hover(function(){ alert("You entered p1!"); }, function(){ alert("Bye! You are now leaving p1!"); });

Some Common Event Methods…  focus()  Executed when the form field gets focus:  $("input").focus(function(){ $(this).css("background- color","#cccccc"); });  blur()  Executed when the form field loses focus

Some Common Event Methods…  Keyboard Events:  The order of events related to the keyboard events: 1. keydown - The key is on its way down 2. keypress - The key is pressed down 3. keyup - The key is released  Use the event.which property to return which keyboard key was pressed.

Some Common Event Methods…  keydown()  Trigger the keydown event for the selected elements: $(selector).keydown()  Attach a function to the keydown event: $(selector).keydown(function)  $("input").keydown(function(){ $("input").css("background- color","yellow"); });

Some Common Event Methods…  keypress()  The keypress() method triggers the keypress event, or attaches a function to run when a keypress event occurs.  The keypress event is similar to the keydown event. The event occurs when a button is pressed down.  However, the keypress event is not fired for all keys (e.g. ALT, CTRL, SHIFT, ESC). Use the keydown() method to also check these keys.  Count the number of key presses in an field: i=0 $("input").keypress(function(){ $("span").text(i+=1); });

Some Common Event Methods…  keyup()  The keyup event occurs when a keyboard key is released.  The keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs.  Set the background colour of an field when a keyboard key is released: $("input").keyup(function(){ $("input").css("background- color","pink"); });

Some Common Event Methods…  The event.which property returns which keyboard key or mouse button was pressed for the event.  $("input").keydown(function(event){ $(“#whatKey").html("Key: " + event.which); });

Now try to implement the following…  User double clicks on a button and gets an error message.  Mouse enters an image and it gets bigger.  Mouse enters a menu item and the background changes; it leaves the menu item and the background returns to the original colour.  User selects the submit button for a form and gets a alert acknowledging that they have submitted the form.