To get an element from a property
1. For example, to get the element with ID in the page p tag
Copy Code code as follows:
$ ("P[id]"). CSS ("Color", "red");
Get an element from a property value
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
Copy Code code as follows:
<input name= "Newsletter"/>
<input name= "Milkman"/>
<input name= "Jobletter"/>
JQuery Code:
Copy Code code as follows:
$ ("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
Copy Code code as follows:
<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:
Copy Code code as follows:
$ ("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:
Copy Code code as follows:
<input name= "Man-news"/>
<input name= "Milkman"/>
<input name= "Letterman2"/>
<input name= "Newmilk"/>
JQuery Code:
Copy Code code as follows:
$ ("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:
Copy Code code as follows:
<input name= "Newsletter"/>
<input name= "Milkman"/>
<input name= "Newsboy"/>
JQuery Code:
Copy Code code as follows:
$ ("input[name^= ' News ']")
Results:
[<input name= "Newsletter"/> <input name= "Newsboy"/>]
6 Gets the specified property and the element with the specified string in the Set value
HTML Code:
Copy Code code as follows:
<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:
Copy Code code as follows:
$ ("input[name$= ' letter '][value$= ' ZZ ']"). attr ("Checked", "true"); Support for multi-condition operations
Of course, you can also get it based on the id attribute or other properties, such as $ ("input[id=id1]"). CSS ("color", red);
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