Skip to content

Commit 2df590e

Browse files
committed
Event: Allow constructing a jQuery.Event without a target
Fixes jquerygh-3139 Closes jquerygh-3140
1 parent 73bf35e commit 2df590e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ jQuery.Event = function( src, props ) {
527527
// Create target properties
528528
// Support: Safari <=6 - 7 only
529529
// Target should not be a text node (#504, #13143)
530-
this.target = ( src.target.nodeType === 3 ) ?
530+
this.target = ( src.target && src.target.nodeType === 3 ) ?
531531
src.target.parentNode :
532532
src.target;
533533

test/unit/event.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,6 +2736,15 @@ QUnit.test( ".off() removes the expando when there's no more data", function( as
27362736
}
27372737
} );
27382738

2739+
QUnit.test( "jQuery.Event( src ) does not require a target property", function( assert ) {
2740+
assert.expect( 2 );
2741+
2742+
var event = jQuery.Event( { type: "offtarget" } );
2743+
2744+
assert.equal( event.type, "offtarget", "correct type" );
2745+
assert.equal( event.target, undefined, "no target" );
2746+
} );
2747+
27392748
QUnit.test( "preventDefault() on focusin does not throw exception", function( assert ) {
27402749
assert.expect( 1 );
27412750

0 commit comments

Comments
 (0)