How to Use filter (), not (), split () find, and filter functions in jQuery

Source: Internet
Author: User

How to Use filter (), not (), split () find, and filter functions in jquery


Filter () and not ():

<Script type = "text/Webpage effects">
$ (Document). ready (function (){
// Output hello
Alert ($ ("p"). filter (". selected" example .html ());
// Output how are you?
Alert ($ ("p"). not (". selected" example .html ());
});
</Script>
</Head>
<Body>
<P class = "selected"> hello </p> <p> how are you? </P>
<! --
A new challenge is to select only one specific element from a group of similar or identical elements.
Jquery provides filter () and not () for this.
Filter () can streamline the elements to only those that meet the filter conditions. not () removes all those that meet the filter conditions. -->
</Body>

Split

<Script type = "text/Webpage effects">
$ (Document). ready (function (){
$ ("Input [@ value = btn1]"). click (function (){
// Separated by ¥
Alert ($ ("span. sale "). text (). split ("¥") [2] + "|" + $ ("span. sale "). text (). split ("¥") [1] + "|" + $ ("span. sale "). text (). split ("¥") [0]);
});
});
</Script>
</Head>
<Body>
Get price: 120 <input type = "button" value = "btn1"> <br>
<Span class = "sale">
Out sale: ¥160 <br/>
Deal price: ¥120 </span>
<! --
Use split to solve this problem. The following is an example of split:
Msg = "2007/10/01 ";
Msg = msg. split ("/");
Alert (msg [2]);
It will divide msg into three parts to form an array, and then it can be easily obtained.
-->
</Body>

It is basically the find sub-element query, and the filter is the level query.

 

The find function is used to query the child element of the current object set;
· The filter function filters the current object set and uses filter conditions to narrow down the scope;
· The parameters of the find function are jquery selector expressions;
· Filter parameters are also selector expressions, but there can be multiple conditions separated by commas (,) (logical or relational );
· The filter parameter can also be a function. The index parameter is automatically input when a function is called. The function must return true or false to be selected or

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.