Step by Step -56-jquery Foundation

Source: Internet
Author: User

The nature of jquery is still encapsulated JS, but the code is more concise, and do better

Using the jquery selector returns a JQuery object, which is essentially a DOM array, and the jquery object can invoke the JQuery method.

1 Basic Selector

1.1 ID Selector

jquery ==> $ (' #btnShow ');

JS ==> document.getElementById (' btnshow ');

1.2 Tag Selector

jquery ==> $ (' img ');
JS ==> document.getelementsbytagname (' img ');

Class 1.3 Selector

JS ==> document.getelementsbyclassname (' Test ');

2 Properties

2.1 Prop represents the original HTML property

2.2 attr denotes extended attributes (more commonly used)

2.3 Properties

2.3.1 Setting properties
$ (' a '). attr (' href ', ' http://www.baidu.com ');

2.3.2 Removing properties

$ (' a '). removeattr (' href ', ' http://www.baidu.com ');

2.3.3 Gets the value of the values property is more special

$ (' #btnShow '). Val ();

2.3.4 Setting the Value property is special

$ (' #btnShow '). Val (' Zhang San ');

    

3 Events

3.1 Way One bind (event type, processing function);

3.2 Mode two event types (processing functions); The event type is the same as in the DOM, and the on prefix is removed.

3.3 Bind a fixed-point click event, remove on, use parentheses

$ (' #btnShow '). Click (function () {
Alert (' anonymous function does parameter ');

alert (this.value);//this is a DOM object and cannot call the jquery method
});

3.4 Uninstallation Events

Unbind ();//Remove all event handlers

Unbind (' Clicke ');//Remove all event handlers

Step by Step -56-jquery Foundation

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.