mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Ensure delegation doesn't error on comment nodes
Fixes gh-2055 Close gh-2659
This commit is contained in:
parent
769446c697
commit
493b0fd7f5
@ -1852,6 +1852,33 @@ QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", funct
|
|||||||
jQuery( "#anchor2" ).trigger( "click" );
|
jQuery( "#anchor2" ).trigger( "click" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
QUnit.test( "ignore comment nodes in event delegation (gh-2055)", function( assert ) {
|
||||||
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
// Test if DOMNodeInserted is supported
|
||||||
|
// This is a back-up for when DOMNodeInserted support
|
||||||
|
// is eventually removed from browsers
|
||||||
|
function test() {
|
||||||
|
var ret = false;
|
||||||
|
var $fixture = jQuery( "#qunit-fixture" );
|
||||||
|
$fixture.on( "DOMNodeInserted", function() {
|
||||||
|
ret = true;
|
||||||
|
$fixture.off( "DOMNodeInserted" );
|
||||||
|
} ).append( "<div></div>" );
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
var $foo = jQuery( "#foo" ).on( "DOMNodeInserted", "[id]", function() {
|
||||||
|
assert.ok( true, "No error thrown on comment node" );
|
||||||
|
} ),
|
||||||
|
$comment = jQuery( document.createComment( "comment" ) )
|
||||||
|
.appendTo( $foo.find( "#sap" ) );
|
||||||
|
|
||||||
|
if ( !test() ) {
|
||||||
|
fireNative( $comment[0], "DOMNodeInserted" );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) {
|
QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) {
|
||||||
assert.expect( 1 );
|
assert.expect( 1 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user