返回值:jQuery contents()
V1.2 概述
查詢匹配元素內部所有的子節點(包括文字節點)。如果元素是一個iframe,則查詢文件內容
示例
描述:
查詢所有文字節點並加粗
HTML 程式碼:
<p>Hello <a href="//ejohn.org/">John</a>, how are you doing?</p>
jQuery 程式碼:
$("p").contents().not("[nodeType=1]").wrap("<b/>");
結果:
<p><b>Hello</b> <a href="//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!");