Monitor a container and pop up when the user clicks
The code is as follows
$(function(){
$("Element").click{function(){
alert("点击我哦!");
}
}
});
Copy after login
Basic object acquisition (note that the Jquery objects obtained here are not Dom objects, but they can be converted)
The code is as follows
$("*") ' means to get all objects, but I have never used it like this
$("#XXX") 'Get the element object with id=XXX (the id can be the tag's id or CSS style id) Commonly used
$("input[name='username']") Get the element object with name='userName' in the input tag. Commonly used
$(".abc") ' Get the element object whose name is .abc. Commonly used
$("div") ' Tag selector selects all div elements. Commonly used
$("#a,.b,span") ' means to get the element whose ID is (www.jb51.net)a, the element using class style b and all span elements
$("#a .b p") 'The ID number is a and uses b style for all p elements
Example
Suppose there is the following code.
var target_obj = jQuery('#target_obj_id');
Then, if you need to determine whether the id is target_obj_id, there are two ways to achieve it:
1,
The code is as follows
if (target_obj.length > 0) { //If greater than 0, the object with ID target_obj_id exists, otherwise it does not exist
//Processing logic for object existence
} else {
//Processing logic for object not existing
}
2.
The code is as follows
if (target_obj[0]) {
//Processing logic for object existence
} else {
//Processing logic for object not existing
}