首页  >  筛选  > contents()

返回值:jQuerycontents()

V1.2jQuery contents() 方法概述

查找匹配元素内部所有的子节点(包括文本节点)。如果元素是一个iframe,则查找文档内容

示例

描述:

查找所有文本节点并加粗

HTML 代码:
<p>Hello <a href="http://ejohn.org/">John</a>, how are you doing?</p>
jQuery 代码:
$("p").contents().not("[nodeType=1]").wrap("<b/>");
结果:
<p><b>Hello</b> <a href="http://ejohn.org/">John</a>, <b>how are you doing?</b></p>

描述:

往一个空框架中加些内容

HTML 代码:
<iframe src="/index-blank.html" width="300" height="100"></iframe>
jQuery 代码:
$("iframe").contents().find("body")
  .append("I'm in an iframe!");