The space in the selector cannot be ignored. A space or a space may have different results. The following example shows the differences in detail, for more information about the amount of friends you are interested in, refer to this article from "sharp jQuery" and add your own stuff.
The space in the selector cannot be ignored. A space or a space may have different results. The following is an example.
First, construct the following HTML code:
The Code is as follows:
Jquery tutorial
Jquery Learning
Jquery plugin
PHP Learning
Jquery plugin tutorial
Jquery plugin Learning
JQuery code:
The Code is as follows:
Var $ test_a = $ (". test: hidden"); // jQuery selector with spaces
Var $ test_ B = $ (". test: hidden"); // jQuery selector without spaces
Var len_a = $ test_a.length;
Var len_ B = $ test_ B .length;
Alert ("The jQuery element selected by the jQuery selector with spaces is:" + len_a + ""); // The output is 4
Alert ("The jQuery element selected by the jQuery selector without spaces is:" + len_ B + ""); // The output is 3
Different results appear, which is the difference between the descendant selector and the filter selector.
The Code is as follows:
Var $ test_a = $ (". test: hidden"); // jQuery selector with spaces
The code above selects the hidden element in the element whose class is "test. (Descendant selector)
The Code is as follows:
Var $ test_ B = $ (". test: hidden"); // jQuery selector without spaces
The above code selects the hidden class as the "test" element.
Note:
Some selector usage must be a space. If there is no space, no element can be obtained. For example:
The Code is as follows:
$ ("Select: selected"). length; // at any time, this selector cannot obtain the element, and the length must be 0.
$ ("Select: selected"); // This is correct.
Some selectors must be used without spaces. If spaces exist, no elements can be obtained. For example:
The Code is as follows:
$ ("Input: checked"). length; // at any time, this selector cannot obtain the element, and the length must be 0.
$ ("Input: checked"); // This is correct.