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