Introduction to the $ selector usage in jquery _jquery
Source: Internet
Author: User
1.$. In jquery $ ("<span>"), this syntax is equivalent to $ (document.createelement ("span"), which is a usage that can be used when selecting elements: [Attribute$=value], Matching a given property is an element that ends with some value. Here is an example to illustrate:
HTML code
<input name= "Newsletter"/>
<input name= "Milkman"/>
<input name= "Jobletter"/>
JQuery Code:
$ ("input[name$= ' letter ']")
Results:
[<input name= "Newsletter"/> <input name= "Jobletter"/>]
2.!. selector: [Attribute!=value], which matches all elements that do not contain the specified property, or the property is not equal to a particular value, which is equivalent to: not ([Attr=value]).
Examples illustrate:
HTML code
<input type= "checkbox" name= "Newsletter" value= "Hot Fuzz"/>
<input type= "checkbox" name= "Newsletter" value= "Cold Fusion"/>
<input type= "checkbox" Name= "Accept" value= "Evil plans"/>
JQuery Code:
$ ("input[name!= ' newsletter ']"). attr ("Checked", true);
Results:
[<input type= "checkbox" Name= "Accept" value= "Evil plans" checked= "true"/>]
3.*. selector: [Attribute*=value], which matches the given property to an element that contains certain values. For example, explain:
HTML Code:
<input name= "Man-news"/>
<input name= "Milkman"/>
<input name= "Letterman2"/>
<input name= "Newmilk"/>
JQuery Code:
$ ("input[name*= ' Man ']")
Results:
[<input name= "Man-news"/> <input name= "Milkman"/> <input name= "letterman2"/>]
4.@. Matches the element that contains the given property. Note that in jquery 1.3, the leading @ symbol has been abolished! If you want to be compatible with the latest version, simply remove the @ symbol
Can
5.^. selector: [Attribute^=value], which matches a given property as an element that starts with some value, and here's an example to illustrate:
HTML Code:
<input name= "Newsletter"/>
<input name= "Milkman"/>
<input name= "Newsboy"/>
JQuery Code:
$ ("input[name^= ' News ']")
Results:
[<input name= "Newsletter"/> <input name= "Newsboy"/>]
In jquery, when using $ ("Input[name= ' Metaid ']"). Val () cannot directly get the value of the selected radio, just get the first value of the radio tag, which may be relevant to jquery using the XPath language to find out. And we usually want to get the value of the selected radio, there are several ways:
1, use $ ("Input[name= ' Metaid ']:checked"). Val () Get//name Representative Name property name in radio
2, use $ (": radio:checked"). Val () Get//Limit page only a set of radio labels
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service