jquery parent, child, sibling node lookup, node's sub node loop method _jquery

Source: Internet
Author: User

Jquery.parent (expr)//Find the parent element

Jquery.parents (expr)//Find all ancestor elements, not limited to parent elements

Jquery.children (expr)//Find all child elements, will only find the direct child node, will not return all descendants

Jquery.contents ()//Find all content below, including nodes and text.

Jquery.prev ()//Find the previous sibling node, not all sibling nodes

Jquery.prevall ()//Find all previous sibling nodes

Jquery.next ()//Find Next sibling node, not all sibling nodes

Jquery.nextall ()//Find all later sibling nodes

Jquery.siblings ()///Find sibling nodes, no points before and after

Jquery.find (expr)//is completely different from jquery.filter (expr), jquery.filter (expr) from the initial

A subset of the jquery objects is filtered out, and the return result of Jquery.find () does not have an initial concentration

Filter out a part, and the return result of Jquery.find () does not have the contents of the initial collection, for example:

$ ("P"). FIND ("span") is to start from the element, equal to $ ("P span")

In jquery we can choose $ (). each () and $.each () to iterate over the object and array

$ (items). each (function () {

   //item

While the latter

$.each (Items,function (i,item) {

//write your code

})
$ ("button"). Click (function () {
 $ ("Li"). each (function () {
  alert ($ (this). Text ())
 }

); $ ("#ID >div"). each (the function () {
     alert ($ (this). attr ("id"));//print the ID of the child Div
});

The loop ID is all input labels under plan_value, and when the label type is a hidden label, get the next tab and manipulate their values

var plan_value_str = "";
          $ ("#plan_value >input"). each (the function () {
             if ($ (this). attr ("type") = = "hidden") {
               if (plan_value_str = = "" {
                 Plan_value_str = $ (this). attr ("value") + "-" +$ (This). Next (). attr ("value");
               } else{
                 plan_value_str = plan_value_str+ ";" +$ (This). attr ("value") + "-" +$ (This). Next (). attr ("value");}}
          ) 
          $ ("#plan_value_str"). Val (PLAN_VALUE_STR);

The above jquery of the parent, child, sibling node lookup, node of the sub-node loop method is small to share all the content of everyone, hope to give you a reference, but also hope that we support cloud habitat community.

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.