diff options
-rw-r--r-- | src/event.js | 5 | ||||
-rw-r--r-- | test/unit/event.js | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/event.js b/src/event.js index 7f66d49de..796d96210 100644 --- a/src/event.js +++ b/src/event.js @@ -4,6 +4,7 @@ import documentElement from "./var/documentElement.js"; import rnothtmlwhite from "./var/rnothtmlwhite.js"; import rcheckableType from "./var/rcheckableType.js"; import slice from "./var/slice.js"; +import acceptData from "./data/var/acceptData.js"; import dataPriv from "./data/var/dataPriv.js"; import nodeName from "./core/nodeName.js"; @@ -109,8 +110,8 @@ jQuery.event = { special, handlers, type, namespaces, origType, elemData = dataPriv.get( elem ); - // Don't attach events to noData or text/comment nodes (but allow plain objects) - if ( !elemData ) { + // Only attach events to objects that accept data + if ( !acceptData( elem ) ) { return; } diff --git a/test/unit/event.js b/test/unit/event.js index 43e2f3857..4019fbe81 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2811,6 +2811,15 @@ QUnit.test( "preventDefault() on focusin does not throw exception", function( as }, QUnit.config.testTimeout / 4 || 1000 ); } ); +QUnit.test( ".on('focus', fn) on a text node doesn't throw", function( assert ) { + assert.expect( 1 ); + + jQuery( document.createTextNode( "text" ) ) + .on( "focus", function() {} ); + + assert.ok( true, "No crash" ); +} ); + QUnit.test( "Donor event interference", function( assert ) { assert.expect( 8 ); |