Use of the filter (), not (), split () in jquery

Source: Internet
Author: User

Filter (), not ():


Program code
<script type= "Text/javascript" >
$ (document). Ready (function () {
Output Hello
Alert ($ ("P"). Filter (". Selected"). html ());
How is the output?
Alert ($ ("P"). Not (". Selected"). html ());
});
</script>

<body>

<p class= "selected" >hello</p><p>how is you?</p>
<!--
A new challenge is to select only one particular element from a set of similar or identical elements.
jquery provides filter () and not () to do this.
Filter () is able to refine the element to only those that satisfy the filter, not () on the contrary, he removes all the conditions that satisfy the condition. -
</body>


Split ():

Program code
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("input[@value =btn1]"). Click (function () {
Split with ¥
Alert ($ ("Span.sale"). Text (). Split ("¥") [2]+ "| |" +$ ("Span.sale"). Text (). Split ("¥") [1]+ "| |" +$ ("Span.sale"). Text (). Split ("¥") [0]);
});

});
</script>

<body>
Get price 120:<input type= "button" value= "BTN1" ><br>

<span class= "Sale" >
Out sale:¥160<br/>
Deal price:¥120</span>


<!--
Apply split to solve this problem. An example of split is given below:
msg = "2007/10/01";
msg = Msg.split ("/");
Alert (msg[2]);
He would divide the msg into an array of 3 blocks, which would then be easily accessible.
-
</body>



Help: Filter in Firefox error, do not know whether I write wrong?

var stext = $ (data). Filter (' #content '). html ();

Data is the content that is retrieved through Ajax, I want to filter, as long as the contents of the content of the ID is the part.
This writing in IE all normal, do not know why in Firefox does not work, with Firebug to find errors, the hint is the 1521th line of jquery-1.2.1.js "f = (' false| | function (a,i) {return ' + F + '} '); " This paragraph has a problem, do not know whether it is a bug, do not know how to deal with. Toss n long, almost collapsed! No way, I just contact jquery, or a small rookie.


This problem has been solved by itself!
I do not know if anyone has the same problem, but I would like to share their experience!
When filtering with filter, fixed data such as march.hu said that (var data = "<p> The first paragraph </p><p id= ' second ' > second paragraph </p>";), this does not matter, However, when using AJAX to retrieve dynamic data for filtering, you must specify both the label type and ID to filter correctly, or you will get an error in Firefox.
Error: var stext = $ (data). Filter (' #content '). html ();
Correct: var stext = $ (data). Filter (' Div#content '). html ();

Use of the filter (), not (), split () in jquery

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.