JQuery Tool class Function-detects the inclusion relationship of two nodes

Source: Internet
Author: User

Calling a $.contains tool function that detects if a DOM node contains another DOM node, if it contains, returns True, otherwise, returns a value of false, called the format:

$.contains (container, contained);

The parameter container represents a DOM object node element that contains a container for other nodes, and contained is another DOM object node element that is contained by other containers.

<body> <div id= "Divtest" > <div class= "title" > <span class= "FL" > Detection of two-node containment relationships &lt ;/span> </div> <div class= "content" ></div> </div> <script type= "Text/ja Vascript ">        $(function () {            varNode_a =Document.body.firstChild; varNode_b =document.body; varstrtmp = "Object Node_a"; if($.contains (node_b,node_a)) {//detect if a node is includedStrtmp + = "contains"; }            Else{strtmp+ = "not included"; } strtmp+ = "Object Node_b"; $(". Content"). HTML (strtmp);    }); </script></body>

Object Node_a contains object Node_b

JQuery Tool class Function-detects the inclusion relationship of two nodes

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.