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"