Fixed #1763 by checking to see if .createElement() is available on the context and if isn't default to other contexts.

This commit is contained in:
David Serduke 2007-12-04 19:37:03 +00:00
parent d938c6bbd6
commit 76e3a90153
2 changed files with 19 additions and 4 deletions

View file

@ -917,6 +917,8 @@ jQuery.extend({
clean: function( elems, context ) { clean: function( elems, context ) {
var ret = []; var ret = [];
context = context || document; context = context || document;
if (!context.createElement)
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
jQuery.each(elems, function(i, elem){ jQuery.each(elems, function(i, elem){
if ( !elem ) if ( !elem )

View file

@ -12,14 +12,19 @@ test("Basic requirements", function() {
}); });
test("$()", function() { test("$()", function() {
expect(5); expect(4);
var main = $("#main"); var main = $("#main");
isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
/*
// disabled since this test was doing nothing. i tried to fix it but i'm not sure
// what the expected behavior should even be. FF returns "\n" for the text node
// make sure this is handled // make sure this is handled
$('<p>\r\n</p>'); var crlfContainer = $('<p>\r\n</p>');
ok( true, "Check for \\r and \\n in jQuery()" ); var x = crlfContainer.contents().get(0).nodeValue;
equals( x, what???, "Check for \\r and \\n in jQuery()" );
*/
/* // Disabled until we add this functionality in /* // Disabled until we add this functionality in
var pass = true; var pass = true;
@ -148,7 +153,7 @@ var foo = false;
test("$('html')", function() { test("$('html')", function() {
expect(4); expect(4);
reset(); reset();
foo = false; foo = false;
var s = $("<script>var foo='test';</script>")[0]; var s = $("<script>var foo='test';</script>")[0];
@ -163,6 +168,14 @@ test("$('html')", function() {
reset(); reset();
}); });
test("$('html', context)", function() {
expect(1);
var $div = $("<div/>");
var $span = $("<span/>", $div);
equals($span.length, 1, "Verify a span created with a div context works");
});
test("length", function() { test("length", function() {
expect(1); expect(1);
ok( $("p").length == 6, "Get Number of Elements Found" ); ok( $("p").length == 6, "Get Number of Elements Found" );