Filtering in jquery

Source: Internet
Author: User

1. Filtering

1.1 eq find element starting from 0

<script type= "Text/javascript" src= ". /jquery-1.7.2.min.js ">
</script>
<script type= "Text/javascript" >
$ (function () {

$ ("li"). EQ (1). CSS ("Background", "red");//Pay attention to the syntax of the CSS here

})

</script>

<body>
<ul>
<li>00000000</li>
<li>11111111</li>
</ul>
</body>

1.2 First () and last () Select a $ ("div") for the initial and final element.

1.3 Filter (expr), which filters the first node of the class, for example: Alert ($ ("P"). Filter (". Selected). html ()); (Remember: expr includes: Tag name, class name, id)

1.3 has (expr) with filter

1.4 Hasclass (class name) checks whether the current element contains a particular class and, if so, returns True.

1.5 is (expr)

An expression is used to examine the currently selected collection of elements, and returns true if at least one of the elements conforms to the given expression.

$("input[type=‘checkbox‘]").parent().is("form")

Returns ' false ' if no element is met, or if the expression is not valid.

1.6 Map (function () {})

Converts a set of elements into other arrays (whether or not an array of elements) (complement: get () to get all matching DOM element collections.

Selects all images in the document as an array of elements and reverses the array using the reverse method built in the array. $("img").get().reverse())

$("input").map(function(){  return $(this).val();}).get().join(", ") );

1.7 not(expr)
To delete an element that matches a specified expression
1.8 Slice () (JS for strings and Arrays slice (index,-1) or 1 omitted, denoted to end)
Slice (INDEX1,INDEX2) selected node for index1-----(index2-1)
2. Find
2.1 Children () parent () prev () [finds the previous sibling element adjacent to each paragraph. ] Next () offsetParent () siblings () [finds all sibling elements of the element] parents () finds all ancestor elements
2.2 Nextuntil () prevuntil () parentuntil ()

<script>
$ (function () {
$ (' li.item-a '). Parentsuntil ('. Level-1 ')
. css (' background-color ', ' red ');

})
</script>

<body>
<ul class= "Level-1" >
<li class= "Item-i" >I</li>
<li class= "Item-ii" >ii
<ul class= "Level-2" >
<li class= "Item-a" >A</li>
<li class= "Item-b" >b
<ul class= "Level-3" >
<li class= "Item-1" >1</li>
<li class= "Item-2" >2</li>
<li class= "Item-3" >3</li>
</ul>
</li>
<li class= "Item-c" >C</li>
</ul>
</li>
<li class= "ITEM-III" >III</li>
</ul>

The 2.3 find () is used to find a node $ ("p span") so write can

2.4 closest () starts with the element itself, and then matches the ancestor element, returning the first matching element.

      Event delegate


$ (function () {

$ (document). Bind ("click", Function (e) {
$ (e.target). Closest ("Li"). Toggleclass ("Hilight");
});
})

3. Tandem

3.1 End ()

Back to a recent "destructive" operation. That is, the list of matched elements changes to the previous state.

3.2 andself ()

Select All div and internal p, plus the Border class

$("div").find("p").andSelf().addClass("border");

<div class="border">    <p class="border">First Paragraph</p>    <p class="border">Second Paragraph</p></div>
3.3 contents ()

Finds all child nodes (including text nodes) within a matching element. If the element is an IFRAME, find the document content

$("iframe").contents().find("body")  .append("I‘m in an iframe!");

Filtering 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.