text: function( text ) {
if ( typeof text != "object" && text != null )
- return this.empty().append( document.createTextNode( text ) );
+ return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
var ret = "";
var obj = this;
if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
- obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
+ obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
var scripts = jQuery( [] );
<!-- Test HTML -->
<div id="nothiddendiv" style="height:1px;background:white;"></div>
+ <!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
+ <iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
<dl id="dl" style="display:none;">
<div id="main" style="display: none;">
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
</select>
<input type="submit" name="sub1" value="NO" />
<input type="submit" name="sub2" value="NO" />
- <input type="image" name="sub3" value="NO" src="submit.gif" />
+ <input type="image" name="sub3" value="NO" />
<button name="sub4" type="submit" value="NO">NO</button>
<input name="D1" type="text" value="NO" disabled="disabled" />
<input type="checkbox" checked="checked" disabled="disabled" name="D2" value="NO" />
reset();
var pass = true;
try {
- $( $("iframe")[0].contentWindow.document.body ).append("<div>test</div>");
+ $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
} catch(e) {
pass = false;
}
});
test("contents()", function() {
- expect(2);
+ expect(10);
equals( $("#ap").contents().length, 9, "Check element contents" );
ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
- // Disabled, randomly fails
- //ok( $("#iframe").contents()[0].body, "Check existance of IFrame body" );
+ var ibody = $("#loadediframe").contents()[0].body;
+ ok( ibody, "Check existance of IFrame body" );
+
+ equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
+
+ $(ibody).append("<div>init text</div>");
+ equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
+
+ equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
+
+ $("div:last", ibody).text("div text");
+ equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
+
+ $("div:last", ibody).remove();
+ equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
+
+ equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
+
+ $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
+ $("table", ibody).remove();
+ equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
});