Let’s look at a piece of code first, it’s very simple, as follows
$("#div1 span") gets an array of three objects
1. If you execute $("#div1 span").html("aaa"), all objects in the array will change. As shown below
2. If you execute $("#div1 span").html() and only get the value, only the value of the first object in the array will be taken
So if the selector is an array and you want to operate on each element of the array, it is best to use each().
There are also some things to note
Precautions for special symbols in the selector. The selector contains special characters such as ".", "#", "(" or "]". According to W3C regulations, attribute values cannot contain these special characters. However, in actual projects, we occasionally encounter special characters such as "#" and "." in expressions. If we process them in the normal way, an error will occur
.The solution to this type of error is to escape using an escape character.
Cannot be written like this:
$('#id#b'); $('#id[1]');
Escape symbols should be used:
$('#id\#b'); //Escape the special character "#"
$('#id\[1\]'); //Escape special characters "[ ]"