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

Source: Internet
Author: User

Filter (), not ():

<Scripttype= "Text/javascript">$ (document). Ready (function() {//Output HelloAlert ($ ("P"). Filter (". Selected"). HTML ());//How is the output?Alert ($ ("P"). Not (". Selected"). HTML ());});</Script> </Head><Body> <Pclass= "Selected">Hello</P><P>How is it?</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 ():

The split () method is used to split a string into an array of strings.
Grammar
Stringobject.split (Separator,howmany)
Parameter description
Separator required. A string or regular expression that splits stringobject from where specified by the parameter.
Howmany is optional. This parameter specifies the maximum length of the returned array. If this parameter is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length.
return value
An array of strings. The array is created by splitting the string stringobject into substrings at the boundary specified by separator. The string in the returned array does not include the separator itself.
However, if separator is a regular expression that contains a subexpression, the returned array includes the strings that match those sub-expressions (but not the text that matches the entire regular expression)
<Scripttype= "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></Head> <Body>Get Price:<inputtype= "button"value= "BTN1" ><BR> <spanclass= "Sale">Out sale:¥160<BR/>Deal price:¥120</span>  <!--apply split to solve this problem.     Here is an example with split: 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.