Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning jQuery, Third Edition

You're reading from   Learning jQuery, Third Edition Create better interaction, design, and web development with simple JavaScript techniques

Arrow left icon
Product type Paperback
Published in Sep 2011
Publisher Packt
ISBN-13 9781849516549
Length 428 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (24) Chapters Close

Learning jQuery Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started FREE CHAPTER 2. Selecting Elements 3. Handling Events 4. Styling and Animating 5. Manipulating the DOM 6. Sending Data with Ajax 7. Using Plugins 8. Developing Plugins 9. Advanced Selectors and Traversing 10. Advanced Events 11. Advanced Effects 12. Advanced DOM Manipulation 13. Advanced Ajax JavaScript Closures Testing JavaScript with QUnit Quick Reference Index

Event methods


In order to react to user behavior, we need to register our handlers using these event methods. Note that many DOM events only apply to certain element types; these subtleties are not covered here. Event methods are discussed in detail in Chapter 3.

Binding

Event Method

Description

.ready(handler)

Bind handler to be called when the DOM and CSS are fully loaded

.bind(type, [data], handler)

Bind handler to be called when the given type of event is sent to the element

.one(type, [data], handler)

Bind handler to be called when the given type of event is sent to the element; removes the binding when the handler is called

.unbind([type], [handler])

Remove the bindings on the element (for an event type, a particular handler, or all bindings)

.live(type, handler)

Bind handler to be called when the given type of event is sent to the element, using event delegation

.die(type, [handler])

Remove the bindings on the element previously bound with .live()

.delegate(selector, type, [data], handler)

Bind handler to be called when the given type of event is sent to a descendant element matching selector

.delegate(selector, handlers)

Bind a map of handlers to be called when the given types of events are sent to a descendant element matching selector

.undelegate(selector, type, [handler])

Remove the bindings on the element previously bound with .delegate()

Shorthand binding

Event Method

Description

.blur(handler)

Bind handler to be called when the element loses keyboard focus

.change(handler)

Bind handler to be called when the element's value changes

.click(handler)

Bind handler to be called when the element is clicked

.dblclick(handler)

Bind handler to be called when the element is double-clicked

.error(handler)

Bind handler to be called when the element receives an error event (browser-dependent)

.focus(handler)

Bind handler to be called when the element gains a keyboard focus

.focusin(handler)

Bind handler to be called when the element, or a descendant, gains a keyboard focus

.focusout(handler)

Bind handler to be called when the element, or a descendant, loses keyboard focus

.keydown(handler)

Bind handler to be called when a key is pressed and the element has keyboard focus

.keypress(handler)

Bind handler to be called when a keystroke occurs and the element has keyboard focus

.keyup(handler)

Bind handler to be called when a key is released and the element has keyboard focus

.load(handler)

Bind handler to be called when the element finishes loading

.mousedown(handler)

Bind handler to be called when the mouse button is pressed within the element

.mouseenter(handler)

Bind handler to be called when the mouse pointer enters the element; not affected by event bubbling

.mouseleave(handler)

Bind handler to be called when the mouse pointer leaves the element; not affected by event bubbling

.mousemove(handler)

Bind handler to be called when the mouse pointer moves within the element

.mouseout(handler)

Bind handler to be called when the mouse pointer leaves the element

.mouseover(handler)

Bind handler to be called when the mouse pointer enters the element

.mouseup(handler)

Bind handler to be called when the mouse button is released within the element

.resize(handler)

Bind handler to be called when the element is resized

.scroll(handler)

Bind handler to be called when the element's scroll position changes

.select(handler)

Bind handler to be called when text in the element is selected

.submit(handler)

Bind handler to be called when the form element is submitted

.unload(handler)

Bind handler to be called when the element is unloaded from memory

Special shorthands

Event Method

Description

.hover(enter, leave)

Bind enter to be called when the mouse enters the element, and leave to be called when the mouse leaves it

.toggle(handler1, handler2, ...)

Bind handler1 to be called when the mouse is clicked on the element, followed by handler2 and so on for subsequent clicks

Triggering

Event Method

Description

.trigger(type, [data])

Trigger handlers for the event on the element, and execute the default action for the event

.triggerHandler(type, [data])

Trigger handlers for the event on the element without executing any default actions

Shorthand triggering

Event Method

Description

.blur()

Trigger the blur event

.change()

Trigger the change event

.click()

Trigger the click event

.dblclick()

Trigger the dblclick event

.error()

Trigger the error event

.focus()

Trigger the focus event

.keydown()

Trigger the keydown event.

.keypress()

Trigger the keypress event

.keyup()

Trigger the keyup event

.select()

Trigger the select event

.submit()

Trigger the submit event

Utility

Event Method

Description

$.proxy(fn, context)

Create a new function that executes with the given context

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image