jQuery的contents()方法

 

概述

查找匹配元素内部所有的子节点(包括文本节点和注释节点(本节点是由元素显示的实际文本))。如果元素是一个iframe,则查找文档内容

语法

$(selector).contents()
 
 

查找 <div> 元素内所有的文本节点,并把它们用 <b> 元素包裹起来:

$("div").contents().filter("em").wrap("<b/>");
 

查找所有文本节点并加粗

<p>ABC<a href="http://tao.me">DEF</a>,hello</p>

$("p").contents().not("[nodeType=1]").wrap("<b/>");

 

往一个空框架中加些内容

<iframe src="iframe-b.html" width="200" height="100"></iframe>

$("iframe").contents().find("body").append("iframe-b "); 

 
posted @ 2017-09-16 10:29  Zel+_+  阅读(241)  评论(0编辑  收藏  举报