jquery Basic Tutorial Chapter 3rd (Increase)

Source: Internet
Author: User

3.2 Handling Simple Events

3.2.1 Simple Style Converter

The. On () method, you can specify any DOM event and add a behavior to the event.

The. Removeclass () method allows you to delete a class for the specified element.

. AddClass () method to add a class.

3.2.3 using the context of an event handler

The $ () function lets you use a DOM element as an argument, and the This keyword as a parameter.

3 jquery Features: 1, the implicit iteration mechanism once again plays a role when each button is bound to the same click event handler by a call to. On ().

2. The behavior queue mechanism allows two functions to be bound on the same click event, and the second function does not overwrite the first function.

3. Use jquery's concatenating ability to compress each operation of the same element into one line of code.

3.2.5 Shorthand Event

$ (' selector '). On (' click ', Function () {}); ==$ (' selector '). Click (function () {});

3.2.6 Show and Hide advanced features

The Toggleclass () method allows you to add a delete class based on the existence of the corresponding class.

3.3 Event Propagation

The. Hover () method. This method accepts two function arguments. The first function executes when the mouse pointer enters the selected element, and the second function fires when the mouse pointer leaves the element.

3.4.4 Event Delegate

Event delegation takes advantage of event bubbling.

. Is () method, receives a selector expression, and then tests the current jquery object with a selector.

3.4.5 using the built-in event delegation function

The. On method The second argument is a selector expression that implements the event delegate. Compares the current jquery object and the selector expression, and if so, the this keyword in the code maps to the matching element.

3.5 Removing event handlers

The. Off () method removes the event handler.

3.5.1 Adding a namespace to an event handler

Introduce additional information when binding an event to identify a specific handler

Such as:

  

function () {        }); $ (' another '). Off (' Click.eventnamespace ');

3.5.2 rebinding Events

$ (document). Ready (function() {    function(event) {        if (!$ (Event.target). Is (' button ')) {            $ (' #switcher button '). Toggleclass (' hidden ');        }    };    $ (' #switcher '). On (' Click.collapse 'toggleswitcher):});

3.6 Emulating User actions

. Trigger () method

jquery Basic Tutorial Chapter 3rd (Increase)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.