Summary of jQuery's simple implementation method for getting objects, and jquery's summary of getting objects

Source: Internet
Author: User

Summary of jQuery's simple implementation method for getting objects, and jquery's summary of getting objects

Monitors a container and pops up when the user clicks

The Code is as follows:

$ (Function () {$ ("Element"). click {function () {alert ("click me! ");}}});

Get basic objects (note that Jquery objects instead of Dom objects are obtained here, but they can be converted)

The Code is as follows:
Copy codeThe Code is as follows:
$ ("*") 'Indicates getting all objects, but I have never used it like this.
$ ("# XXX") 'obtain the Element Object id = XXX (id can be the tag id or CSS style id)
$ ("Input [name = 'username']") obtain the Element Object name = 'username' in the input tag.
$ (". Abc") 'to obtain the style class name is. abc element object commonly used
$ ("Div") 'tag selector Selects all div elements commonly used
$ ("# A,. B, span") 'indicates to obtain the element of ID (www.jb51.net) a, the element that uses class style B, and all span elements.
$ ("# A. B p") 'id is a and all p elements in the B style are used.

Example

Suppose there is the following code.

Copy codeThe Code is as follows:
Var target_obj = jQuery ('# target_obj_id ');

To determine whether the id is target_obj_id, You can implement the following two methods:

1,

The Code is as follows:
Copy codeThe Code is as follows:
If (target_obj.length> 0) {// if the object with the id target_obj_id is greater than 0, otherwise it does not exist

// Processing logic of the object

} Else {

// Processing logic of the object that does not exist

}

2,

The Code is as follows:
Copy codeThe Code is as follows:
If (target_obj [0]) {

// Processing logic of the object

} Else {

// Processing logic of the object that does not exist

}


How does jQuery obtain the currently clicked object?

The method added in jQuery 1.3. Binding an event processing example to all current and future matching elements click to generate p still has the same function. HTML code:

Jquery retrieves objects

Is this

Related Article

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.