Home > Web Front-end > JS Tutorial > Introduction to the usage of $ selector in JQuery_jquery

Introduction to the usage of $ selector in JQuery_jquery

WBOY
Release: 2016-05-16 18:08:32
Original
964 people have browsed it

1.$. In jQuery, $(""), this syntax is equivalent to $(document.createElement("span")). This is a usage. It is also used like this when selecting elements: [attribute$= value], matches elements whose given attribute ends with some value. Here is an example to illustrate:
HTML code



jQuery code:
$("input[name$='letter ']")
Result:
[ , ]
2.!. Selector: [attribute!=value], matches all elements that do not contain the specified attribute, or the attribute is not equal to a specific value. This selector is equivalent to: not ([attr=value]).
Example:
HTML code



jQuery code:
$("input[name!='newsletter' ]").attr("checked", true);
Result:
[ ]
3.*. Selector: [attribute*=value], matches the given attribute to elements containing certain values. Let’s give an example:
HTML code:




jQuery code:
$("input[ name*='man']")
Result:
[ , , ]
4.@. Matches elements containing the given attribute. Note that in jQuery 1.3, the leading @ symbol has been deprecated! If you want to be compatible with the latest version, simply remove the @ symbol
.
5.^. Selector: [attribute^=value], matches elements whose given attributes start with certain values. Here is an example to illustrate:
HTML code:



jQuery code:
$("input[name^='news']")
Result:
[ , ]

In jquery, when using $("input[name='metaId']").val(), you cannot directly get the value of the selected radio, but only get the first value of the radio tag. This may be because jquery uses xpath Language is related to search, and we usually want to get the value of the selected radio. There are several methods:
1, use $("input[name='metaId']:checked").val() Obtain //name represents the name attribute name in radio
2, use $(":radio:checked").val() to obtain //limit the page to only one set of radio tags

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template