// A method for determining if a DOM node can handle the data expando
acceptData: function( elem ) {
+ // Do not set data on non-element because it will not be cleared (#8335).
+ if ( elem.nodeType && elem.nodeType !== 1 && elem.nodeType !== 9 ) {
+ return false;
+ }
+
var noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ];
// nodes accept data unless otherwise specified; rejection can be conditional
QUnit.expectJqData(document, "foo");
});
+test("Data is not being set on comment and text nodes", function() {
+ expect(2);
+
+ ok( !jQuery.hasData( jQuery("<!-- comment -->").data("foo", 0) ) );
+ ok( !jQuery.hasData( jQuery("<span>text</span>").contents().data("foo", 0) ) );
+
+});
+
test("jQuery.acceptData", function() {
- expect(7);
+ expect(9);
ok( jQuery.acceptData( document ), "document" );
ok( jQuery.acceptData( document.documentElement ), "documentElement" );
var applet = document.createElement("object");
applet.setAttribute("classid", "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93");
ok( !jQuery.acceptData( applet ), "applet" );
+
+ ok( !jQuery.acceptData( document.createComment("") ), "comment" );
+ ok( !jQuery.acceptData( document.createTextNode("") ), "text" );
});
test(".data()", function() {