"The node type of the new-JQ"

Source: Internet
Author: User

Source: http://www.hi-docs.com/jquery/contents.html

Definition and usage

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

Grammar
Contents ()
Example 1

Find all text nodes and bold

# HTML Code:
<p>hello <a href= "http://ejohn.org/" >JOHN</A>, how is you doing?</p>
# jQuery Code:
$ ("P"). Contents (). Not ("[nodetype=1]"). Wrap ("<b/>");//Expired
Please use filter instead
$ ("P"). Contents (). filter (function () {return this.nodetype! = 1;}). Wrap ("<b/>");
NodeType represents node Type: 1 element node, 2 attribute node, 3 text node
Results:

<p><b>Hello</b> <a href= "http://ejohn.org/" >JOHN</A>, <b>how is you doing?</ B></p>
Example 2

Find a label and replace its contents

<script type= ' text/javascript ' src= ' jquery.min.js?ver=3.4.2 ' ></script>
<body><div id= "T" ><a>11</a><a>22</a><em>www.hi-docs.com</em> </div>
<script type= "Text/javascript" >$ (' div '). Contents (). Filter (' a '). Text (' Hi bean shell ');</script>
</body>
Results:

Hi bean shell Hi Bean shell www.hi-docs.com
Get the IFRAME content, note: The IFRAME content must be in the same domain

<script src= "Http://ajax.useso.com/ajax/libs/jquery/1.7.2/jquery.min.js" ></script>
<iframe src= "error.html" ></iframe>
<button id= "Get_iframe" > Get ifrmae content </button>
<script type= "Text/javascript" >
$ (' #get_iframe '). Click (function () {
Alert (' iframe '). Contents (). text ());
})
</script>

"The node type of the new-JQ"

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.