$ Selector usage in JQuery _ jquery

Source: Internet
Author: User
In jQuery $ (& quot; & lt; span & gt; & quot;), this syntax is equivalent to $ (document. createElement (& quot; span & quot;), which is a usage 1. $. In jQuery $ (""), this syntax is equivalent to $ (document. createElement ("span"), which is a usage. when selecting an element, [attribute $ = value], matches the given attribute with elements ending with some values. The following is an example:
HTML code



JQuery code:
$ ("Input [name $ = 'Letter ']")
Result:
[ , ]
2 .!. Selector: [attribute! = Value]: matches all elements that do not contain the specified attribute or that are not equal to the specified 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]. matching a given attribute is an element that contains some values. For example:
HTML code:




JQuery code:
$ ("Input [name * = 'man']")
Result:
[ , , ]
4 .@. Matches the element that contains the given attribute. Note: In jQuery 1.3, the leading @ symbol has been abolished! To be compatible with the latest version, simply remove the @ symbol
Yes.
5. ^. Selector: [attribute ^ = value]. matching a given attribute is an element starting with some values. The following is an example:
HTML code:



JQuery code:
$ ("Input [name ^ = 'News']")
Result:
[ , ]

In jquery, when $ ("input [name = 'metaid ']") is used. val () cannot directly obtain the selected radio value, but only obtain the first value of the radio tag. This may be related to jquery's search using the xpath language, we usually want to obtain the selected radio value. There are several methods:
1. Use $ ("input [name = 'metaid ']: checked"). val () to get // name to represent the name attribute name in radio.
2. Use $ (": radio: checked"). val () to get // restrict only one set of radio tags on the page

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.