} catch (e) {}
});
-test("bind(),on(),delegate() with non-null,defined data", function() {
+test("on() with non-null,defined data", function() {
- expect(3);
+ expect(2);
var handler = function( event, data ) {
equal( data, 0, "non-null, defined data (zero) is correctly passed" );
};
- jQuery("#foo").bind("foo.bind", handler);
jQuery("#foo").on("foo.on", handler);
- jQuery("div").delegate("#foo", "foo.delegate", handler);
+ jQuery("div").on("foo.delegate", "#foo", handler);
jQuery("#foo").trigger("foo", 0);
- jQuery("#foo").unbind("foo.bind", handler);
jQuery("#foo").off("foo.on", handler);
- jQuery("div").undelegate("#foo", "foo.delegate");
+ jQuery("div").off("foo.delegate", "#foo");
});
markup.remove();
});
-test("bind(), with data", function() {
+test("on(), with data", function() {
expect(4);
var handler = function(event) {
- ok( event.data, "bind() with data, check passed data exists" );
- equal( event.data["foo"], "bar", "bind() with data, Check value of passed data" );
+ ok( event.data, "on() with data, check passed data exists" );
+ equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
};
- jQuery("#firstp").bind("click", {"foo": "bar"}, handler).trigger("click").unbind("click", handler);
+ jQuery("#firstp").on("click", {"foo": "bar"}, handler).trigger("click").off("click", handler);
ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
var test = function(){};
var handler2 = function(event) {
- equal( event.data, test, "bind() with function data, Check value of passed data" );
+ equal( event.data, test, "on() with function data, Check value of passed data" );
};
- jQuery("#firstp").bind("click", test, handler2).trigger("click").unbind("click", handler2);
+ jQuery("#firstp").on("click", test, handler2).trigger("click").off("click", handler2);
});
test("click(), with data", function() {
expect(3);
var handler = function(event) {
- ok( event.data, "bind() with data, check passed data exists" );
- equal( event.data["foo"], "bar", "bind() with data, Check value of passed data" );
+ ok( event.data, "on() with data, check passed data exists" );
+ equal( event.data["foo"], "bar", "on() with data, Check value of passed data" );
};
- jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").unbind("click", handler);
+ jQuery("#firstp").on( "click", {"foo": "bar"}, handler).trigger("click").off("click", handler);
ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
});
-test("bind(), with data, trigger with data", function() {
+test("on(), with data, trigger with data", function() {
expect(4);
var handler = function(event, data) {
ok( event.data, "check passed data exists" );
ok( data, "Check trigger data" );
equal( data.bar, "foo", "Check value of trigger data" );
};
- jQuery("#firstp").bind("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).unbind("click", handler);
+ jQuery("#firstp").on("click", {foo: "bar"}, handler).trigger("click", [{bar: "foo"}]).off("click", handler);
});
-test("bind(), multiple events at once", function() {
+test("on(), multiple events at once", function() {
expect(2);
var clickCounter = 0,
mouseoverCounter = 0;
}
};
- jQuery("#firstp").bind("click mouseover", handler).trigger("click").trigger("mouseover");
- equal( clickCounter, 1, "bind() with multiple events at once" );
- equal( mouseoverCounter, 1, "bind() with multiple events at once" );
+ jQuery("#firstp").on("click mouseover", handler).trigger("click").trigger("mouseover");
+ equal( clickCounter, 1, "on() with multiple events at once" );
+ equal( mouseoverCounter, 1, "on() with multiple events at once" );
});
-test("bind(), five events at once", function() {
+test("on(), five events at once", function() {
expect(1);
var count = 0,
count++;
};
- jQuery("#firstp").bind("click mouseover foo bar baz", handler)
+ jQuery("#firstp").on("click mouseover foo bar baz", handler)
.trigger("click").trigger("mouseover")
.trigger("foo").trigger("bar")
.trigger("baz");
- equal( count, 5, "bind() five events at once" );
+ equal( count, 5, "on() five events at once" );
});
-test("bind(), multiple events at once and namespaces", function() {
+test("on(), multiple events at once and namespaces", function() {
expect(7);
var cur, obj = {};
- var div = jQuery("<div/>").bind("focusin.a", function(e) {
+ var div = jQuery("<div/>").on("focusin.a", function(e) {
equal( e.type, cur, "Verify right single event was fired." );
});
// manually clean up detached elements
div.remove();
- div = jQuery("<div/>").bind("click mouseover", obj, function(e) {
+ div = jQuery("<div/>").on("click mouseover", obj, function(e) {
equal( e.type, cur, "Verify right multi event was fired." );
equal( e.data, obj, "Make sure the data came in correctly." );
});
// manually clean up detached elements
div.remove();
- div = jQuery("<div/>").bind("focusin.a focusout.b", function(e) {
+ div = jQuery("<div/>").on("focusin.a focusout.b", function(e) {
equal( e.type, cur, "Verify right multi event was fired." );
});
div.remove();
});
-test("bind(), namespace with special add", function() {
+test("on(), namespace with special add", function() {
expect(27);
- var div = jQuery("<div/>").bind("test", function(e) {
+ var div = jQuery("<div/>").on("test", function(e) {
ok( true, "Test event fired." );
});
}
};
- div.bind("test.a", {"x": 1}, function(e) {
+ div.on("test.a", {"x": 1}, function(e) {
ok( !!e.xyz, "Make sure that the data is getting passed through." );
equal( e.data["x"], 1, "Make sure data is attached properly." );
});
- div.bind("test.b", {"x": 2}, function(e) {
+ div.on("test.b", {"x": 2}, function(e) {
ok( !!e.xyz, "Make sure that the data is getting passed through." );
equal( e.data["x"], 2, "Make sure data is attached properly." );
});
div.trigger("test.b", { year: 1982 });
// Should trigger 4
- div.unbind("test");
+ div.off("test");
- div = jQuery("<div/>").bind("test", function(e) {
+ div = jQuery("<div/>").on("test", function(e) {
ok( true, "Test event fired." );
});
delete jQuery.event.special["test"];
});
-test("bind(), no data", function() {
+test("on(), no data", function() {
expect(1);
var handler = function(event) {
ok ( !event.data, "Check that no data is added to the event object" );
};
- jQuery("#firstp").bind("click", handler).trigger("click");
+ jQuery("#firstp").on("click", handler).trigger("click");
});
-test("bind/one/unbind(Object)", function(){
+test("on/one/off(Object)", function(){
expect(6);
var clickCounter = 0, mouseoverCounter = 0;
var $elem = jQuery("#firstp")
// Regular bind
- .bind({
+ .on({
"click":handler,
"mouseover":handler
})
trigger();
- equal( clickCounter, 3, "bind(Object)" );
- equal( mouseoverCounter, 3, "bind(Object)" );
+ equal( clickCounter, 3, "on(Object)" );
+ equal( mouseoverCounter, 3, "on(Object)" );
trigger();
- equal( clickCounter, 4, "bind(Object)" );
- equal( mouseoverCounter, 4, "bind(Object)" );
+ equal( clickCounter, 4, "on(Object)" );
+ equal( mouseoverCounter, 4, "on(Object)" );
- jQuery("#firstp").unbind({
+ jQuery("#firstp").off({
"click":handler,
"mouseover":handler
});
trigger();
- equal( clickCounter, 4, "bind(Object)" );
- equal( mouseoverCounter, 4, "bind(Object)" );
+ equal( clickCounter, 4, "on(Object)" );
+ equal( mouseoverCounter, 4, "on(Object)" );
});
-test("on/off(Object), delegate/undelegate(String, Object)", function() {
+test("on/off(Object), on/off(Object, String)", function() {
expect(6);
var clickCounter = 0,
}
jQuery( document ).on( events, "#firstp a" );
- $p.delegate( "a", events, 2 );
+ $p.on( events, "a", 2 );
trigger();
- equal( clickCounter, 3, "on/delegate" );
- equal( mouseoverCounter, 3, "on/delegate" );
+ equal( clickCounter, 3, "on" );
+ equal( mouseoverCounter, 3, "on" );
- $p.undelegate( "a", events );
+ $p.off( events, "a" );
trigger();
- equal( clickCounter, 4, "undelegate" );
- equal( mouseoverCounter, 4, "undelegate" );
+ equal( clickCounter, 4, "off" );
+ equal( mouseoverCounter, 4, "off" );
jQuery( document ).off( events, "#firstp a" );
equal( mouseoverCounter, 4, "off" );
});
-test("on/delegate immediate propagation", function() {
+test("on immediate propagation", function() {
expect(2);
var lastClick,
jQuery( document ).off( "click", "#firstp a" );
lastClick = "";
- $p.delegate( "a", "click", function(e) {
+ $p.on( "click", "a", function(e) {
lastClick = "click1";
e.stopImmediatePropagation();
});
- $p.delegate( "a", "click", function(e) {
+ $p.on( "click", "a", function(e) {
lastClick = "click2";
});
$a.trigger( "click" );
- equal( lastClick, "click1", "delegate stopImmediatePropagation" );
- $p.undelegate( "click" );
+ equal( lastClick, "click1", "on stopImmediatePropagation" );
+ $p.off( "click", "**" );
});
-test("bind/delegate bubbling, isDefaultPrevented", function() {
+test("on bubbling, isDefaultPrevented", function() {
expect(2);
var $anchor2 = jQuery( "#anchor2" ),
$main = jQuery( "#qunit-fixture" ),
$anchor2.on( "click", function(e) {
e.preventDefault();
});
- $main.delegate("#foo", "click", function(e) {
+ $main.on("click", "#foo", function(e) {
var orig = e.originalEvent;
if ( typeof(orig.defaultPrevented) === "boolean" || typeof(orig.returnValue) === "boolean" || orig["getPreventDefault"] ) {
}
});
fakeClick( $anchor2 );
- $anchor2.unbind( "click" );
- $main.undelegate( "click" );
+ $anchor2.off( "click" );
+ $main.off( "click", "**" );
$anchor2.on( "click", function(e) {
// Let the default action occur
});
- $main.delegate("#foo", "click", function(e) {
+ $main.on("click", "#foo", function(e) {
equal( e.isDefaultPrevented(), false, "isDefaultPrevented false passed to bubbled event" );
});
fakeClick( $anchor2 );
- $anchor2.unbind( "click" );
- $main.undelegate( "click" );
+ $anchor2.off( "click" );
+ $main.off( "click", "**" );
});
-test("bind(), iframes", function() {
+test("on(), iframes", function() {
expect( 1 );
// events don't work with iframes, see #939 - this test fails in IE because of contentDocument
var doc = jQuery("#loadediframe").contents();
- jQuery("div", doc).bind("click", function() {
+ jQuery("div", doc).on("click", function() {
ok( true, "Binding to element inside iframe" );
- }).trigger("click").unbind("click");
+ }).trigger("click").off("click");
});
-test("bind(), trigger change on select", function() {
+test("on(), trigger change on select", function() {
expect(5);
var counter = 0;
function selectOnChange(event) {
equal( event.data, counter++, "Event.data is not a global event object" );
}
jQuery("#form select").each(function(i){
- jQuery(this).bind("change", i, selectOnChange);
+ jQuery(this).on("change", i, selectOnChange);
}).trigger("change");
});
-test("bind(), namespaced events, cloned events", 18, function() {
+test("on(), namespaced events, cloned events", 18, function() {
var firstp = jQuery( "#firstp" );
- firstp.bind("custom.test",function(e){
+ firstp.on("custom.test",function(e){
ok(false, "Custom event triggered");
});
- firstp.bind("click",function(e){
+ firstp.on("click",function(e){
ok(true, "Normal click triggered");
equal( e.type + e.namespace, "click", "Check that only click events trigger this fn" );
});
- firstp.bind("click.test",function(e){
+ firstp.on("click.test",function(e){
var check = "click";
ok( true, "Namespaced click triggered" );
if ( e.namespace ) {
firstp.trigger("click.test");
// Remove only the one fn
- firstp.unbind("click.test");
+ firstp.off("click.test");
// Trigger the remaining fn (4)
firstp.trigger("click");
// Remove the remaining namespaced fn
- firstp.unbind(".test");
+ firstp.off(".test");
// Try triggering the custom event (0)
firstp.trigger("custom");
// using contents will get comments regular, text, and comment nodes
- jQuery("#nonnodes").contents().bind("tester", function () {
- equal(this.nodeType, 1, "Check node,textnode,comment bind just does real nodes" );
+ jQuery("#nonnodes").contents().on("tester", function () {
+ equal(this.nodeType, 1, "Check node,textnode,comment on just does real nodes" );
}).trigger("tester");
// Make sure events stick with appendTo'd elements (which are cloned) #2027
ok( jQuery("a.test").eq(0).triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
});
-test("bind(), multi-namespaced events", function() {
+test("on(), multi-namespaced events", function() {
expect(6);
var order = [
deepEqual(name, order.shift(), msg);
}
- jQuery("#firstp").bind("custom.test",function(e){
+ jQuery("#firstp").on("custom.test",function(e){
check("custom.test", "Custom event triggered");
});
- jQuery("#firstp").bind("custom.test2",function(e){
+ jQuery("#firstp").on("custom.test2",function(e){
check("custom.test2", "Custom event triggered");
});
- jQuery("#firstp").bind("click.test",function(e){
+ jQuery("#firstp").on("click.test",function(e){
check("click.test", "Normal click triggered");
});
- jQuery("#firstp").bind("click.test.abc",function(e){
+ jQuery("#firstp").on("click.test.abc",function(e){
check("click.test.abc", "Namespaced click triggered");
});
- // Those would not trigger/unbind (#5303)
+ // Those would not trigger/off (#5303)
jQuery("#firstp").trigger("click.a.test");
- jQuery("#firstp").unbind("click.a.test");
+ jQuery("#firstp").off("click.a.test");
// Trigger both bound fn (1)
jQuery("#firstp").trigger("click.test.abc");
jQuery("#firstp").trigger("click.test");
// Remove only the one fn
- jQuery("#firstp").unbind("click.abc");
+ jQuery("#firstp").off("click.abc");
// Trigger the remaining fn (1)
jQuery("#firstp").trigger("click");
// Remove the remaining fn
- jQuery("#firstp").unbind(".test");
+ jQuery("#firstp").off(".test");
// Trigger the remaining fn (1)
jQuery("#firstp").trigger("custom");
.off("whoops");
});
-test("bind(), with same function", function() {
+test("on(), with same function", function() {
expect(2);
var count = 0, func = function(){
count++;
};
- jQuery("#liveHandlerOrder").bind("foo.bar", func).bind("foo.zar", func);
+ jQuery("#liveHandlerOrder").on("foo.bar", func).on("foo.zar", func);
jQuery("#liveHandlerOrder").trigger("foo.bar");
equal(count, 1, "Verify binding function with multiple namespaces." );
- jQuery("#liveHandlerOrder").unbind("foo.bar", func).unbind("foo.zar", func);
+ jQuery("#liveHandlerOrder").off("foo.bar", func).off("foo.zar", func);
jQuery("#liveHandlerOrder").trigger("foo.bar");
equal(count, 1, "Verify that removing events still work." );
});
-test("bind(), make sure order is maintained", function() {
+test("on(), make sure order is maintained", function() {
expect(1);
var elem = jQuery("#firstp"), log = [], check = [];
jQuery.each( new Array(100), function( i ) {
- elem.bind( "click", function(){
+ elem.on( "click", function(){
log.push( i );
});
equal( log.join(","), check.join(","), "Make sure order was maintained." );
- elem.unbind("click");
+ elem.off("click");
});
-test("bind(), with different this object", function() {
+test("on(), with different this object", function() {
expect(4);
var thisObject = { myThis: true },
data = { myData: true },
handler1 = function( event ) {
- equal( this, thisObject, "bind() with different this object" );
+ equal( this, thisObject, "on() with different this object" );
},
handler2 = function( event ) {
- equal( this, thisObject, "bind() with different this object and data" );
- equal( event.data, data, "bind() with different this object and data" );
+ equal( this, thisObject, "on() with different this object and data" );
+ equal( event.data, data, "on() with different this object and data" );
};
jQuery("#firstp")
- .bind("click", jQuery.proxy(handler1, thisObject)).trigger("click").unbind("click", handler1)
- .bind("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").unbind("click", handler2);
+ .on("click", jQuery.proxy(handler1, thisObject)).trigger("click").off("click", handler1)
+ .on("click", data, jQuery.proxy(handler2, thisObject)).trigger("click").off("click", handler2);
ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using different this object and data." );
});
-test("bind(name, false), unbind(name, false)", function() {
+test("on(name, false), off(name, false)", function() {
expect(3);
var main = 0;
- jQuery("#qunit-fixture").bind("click", function(e){ main++; });
+ jQuery("#qunit-fixture").on("click", function(e){ main++; });
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
- jQuery("#ap").bind("click", false);
+ jQuery("#ap").on("click", false);
jQuery("#ap").trigger("click");
equal( main, 0, "Verify that no bubble happened." );
main = 0;
- jQuery("#ap").unbind("click", false);
+ jQuery("#ap").off("click", false);
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
// manually clean up events from elements outside the fixture
- jQuery("#qunit-fixture").unbind("click");
+ jQuery("#qunit-fixture").off("click");
});
-test("delegate(selector, name, false), undelegate(selector, name, false)", function() {
+test("on(name, selector, false), off(name, selector, false)", function() {
expect(3);
var main = 0;
- jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; });
+ jQuery("#qunit-fixture").on("click", "#ap", function(e){ main++; });
jQuery("#ap").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
main = 0;
- jQuery("#ap").delegate("#groups", "click", false);
+ jQuery("#ap").on("click", "#groups", false);
jQuery("#groups").trigger("click");
equal( main, 0, "Verify that no bubble happened." );
main = 0;
- jQuery("#ap").undelegate("#groups", "click", false);
+ jQuery("#ap").off("click", "#groups", false);
jQuery("#groups").trigger("click");
equal( main, 1, "Verify that the trigger happened correctly." );
- jQuery("#qunit-fixture").undelegate("#ap", "click");
+ jQuery("#qunit-fixture").off("click", "#ap");
});
-test("bind()/trigger()/unbind() on plain object", function() {
+test("on()/trigger()/off() on plain object", function() {
expect( 7 );
var obj = {};
jQuery(obj).trigger("test");
// Make sure it doesn't complain when no events are found
- jQuery(obj).unbind("test");
+ jQuery(obj).off("test");
- jQuery(obj).bind({
+ jQuery(obj).on({
"test": function() {
ok( true, "Custom event run." );
},
jQuery(obj).trigger("test");
jQuery(obj).trigger("submit");
- jQuery(obj).unbind("test");
- jQuery(obj).unbind("submit");
+ jQuery(obj).off("test");
+ jQuery(obj).off("submit");
// Should trigger 0
jQuery(obj).trigger("test");
// Make sure it doesn't complain when no events are found
- jQuery(obj).unbind("test");
+ jQuery(obj).off("test");
equal( obj && obj[ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ] &&
obj[ jQuery.expando ][ jQuery.expando ]["events"], undefined, "Make sure events object is removed" );
});
-test("unbind(type)", function() {
+test("off(type)", function() {
expect( 1 );
var $elem = jQuery("#firstp"),
}
message = "unbind passing function";
- $elem.bind("error1", error).unbind("error1", error).triggerHandler("error1");
+ $elem.on("error1", error).off("error1", error).triggerHandler("error1");
message = "unbind all from event";
- $elem.bind("error1", error).unbind("error1").triggerHandler("error1");
+ $elem.on("error1", error).off("error1").triggerHandler("error1");
message = "unbind all";
- $elem.bind("error1", error).unbind().triggerHandler("error1");
+ $elem.on("error1", error).off().triggerHandler("error1");
message = "unbind many with function";
- $elem.bind("error1 error2",error)
- .unbind("error1 error2", error )
+ $elem.on("error1 error2",error)
+ .off("error1 error2", error )
.trigger("error1").triggerHandler("error2");
message = "unbind many"; // #3538
- $elem.bind("error1 error2", error)
- .unbind("error1 error2")
+ $elem.on("error1 error2", error)
+ .off("error1 error2")
.trigger("error1").triggerHandler("error2");
message = "unbind without a type or handler";
- $elem.bind("error1 error2.test",error)
- .unbind()
+ $elem.on("error1 error2.test",error)
+ .off()
.trigger("error1").triggerHandler("error2");
// Should only unbind the specified function
- jQuery( document ).bind( "click", function(){
+ jQuery( document ).on( "click", function(){
ok( true, "called handler after selective removal");
});
var func = function(){ };
jQuery( document )
- .bind( "click", func )
- .unbind( "click", func )
+ .on( "click", func )
+ .off( "click", func )
.trigger("click")
- .unbind( "click" );
+ .off( "click" );
});
-test("unbind(eventObject)", function() {
+test("off(eventObject)", function() {
expect(4);
var $elem = jQuery("#firstp"),
$elem
// This handler shouldn't be unbound
- .bind("foo", function(){
+ .on("foo", function(){
num += 1;
})
- .bind("foo", function(e){
- $elem.unbind( e );
+ .on("foo", function(e){
+ $elem.off( e );
num += 2;
})
// Neither this one
- .bind("bar", function(){
+ .on("bar", function(){
num += 4;
});
assert( 7 );
assert( 5 );
- $elem.unbind("bar");
+ $elem.off("bar");
assert( 1 );
- $elem.unbind();
+ $elem.off();
assert( 0 );
});
jQuery("#firstp")
.hover(handler1, handler2)
.mouseenter().mouseleave()
- .unbind("mouseenter", handler1)
- .unbind("mouseleave", handler2)
+ .off("mouseenter", handler1)
+ .off("mouseleave", handler2)
.hover(handler1)
.mouseenter().mouseleave()
- .unbind("mouseenter mouseleave", handler1)
+ .off("mouseenter mouseleave", handler1)
.mouseenter().mouseleave();
equal( times, 4, "hover handlers fired" );
jQuery("#qunit-fixture").append("<div id='jc-outer'><div id='jc-inner'></div></div>");
- jQuery("#jc-outer").bind("mouseenter mouseleave", function( event ) {
+ jQuery("#jc-outer").on("mouseenter mouseleave", function( event ) {
equal( this.id, "jc-outer", this.id + " " + event.type );
jQuery("#jc-inner").trigger("mousenter");
- jQuery("#jc-outer").unbind("mouseenter mouseleave").remove();
+ jQuery("#jc-outer").off("mouseenter mouseleave").remove();
jQuery("#jc-inner").remove();
});
expect(6);
var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
- elem.find("a").bind("click", function() {
+ elem.find("a").on("click", function() {
var close = jQuery("spanx", this); // same with jQuery(this).find("span");
equal( close.length, 0, "Context element does not exist, length must be zero" );
ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
- jQuery(window).bind("click", function(e){ win++; });
- jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
- jQuery("html").bind("click", function(e){ html++; });
- jQuery("body").bind("click", function(e){ body++; });
- jQuery("#qunit-fixture").bind("click", function(e){ main++; });
- jQuery("#ap").bind("click", function(){ ap++; return false; });
+ jQuery(window).on("click", function(e){ win++; });
+ jQuery(document).on("click", function(e){ if ( e.target !== document) { doc++; } });
+ jQuery("html").on("click", function(e){ html++; });
+ jQuery("body").on("click", function(e){ body++; });
+ jQuery("#qunit-fixture").on("click", function(e){ main++; });
+ jQuery("#ap").on("click", function(){ ap++; return false; });
jQuery("html").trigger("click");
equal( win, 1, "HTML bubble" );
equal( win, 4, "doc bubble" );
// manually clean up events from elements outside the fixture
- jQuery(document).unbind("click");
- jQuery("html, body, #qunit-fixture").unbind("click");
+ jQuery(document).off("click");
+ jQuery("html, body, #qunit-fixture").off("click");
});
test("trigger(type, [data], [fn])", function() {
// Triggers handlers and native
// Trigger 5
- $elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
+ $elem.on("click", handler).trigger("click", [1, "2", "abc"]);
// Simulate a "native" click
$elem[0].click = function(){
pass = true;
try {
- jQuery("#qunit-fixture table").eq(0).bind("test:test", function(){}).trigger("test:test");
+ jQuery("#qunit-fixture table").eq(0).on("test:test", function(){}).trigger("test:test");
} catch (e) {
pass = false;
}
// Make sure it can be prevented locally
form.on( "submit", function(){
- ok( true, "Local bind still works." );
+ ok( true, "Local `on` still works." );
return false;
});
// Trigger 1
form.trigger("submit");
- form.unbind("submit");
+ form.off("submit");
jQuery(document).on( "submit", function(){
ok( true, "Make sure bubble works up to document." );
// Trigger 1
form.trigger("submit");
- jQuery(document).unbind("submit");
+ jQuery(document).off("submit");
form.remove();
});
equal( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
equal( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
- $parent.bind("foo",function(e){
+ $parent.on("foo",function(e){
// Tries bubbling
equal( e.type, "foo", "Verify event type when passed passing an event object" );
equal( e.target.id, "child", "Verify event.target when passed passing an event object" );
// test with a literal object
$child.trigger({"type": "foo", "secret": "boo!"});
- $parent.unbind();
+ $parent.off();
function error(){
ok( false, "This assertion shouldn't be reached");
}
- $parent.bind("foo", error );
+ $parent.on("foo", error );
- $child.bind("foo",function(e, a, b, c ){
+ $child.on("foo",function(e, a, b, c ){
equal( arguments.length, 4, "Check arguments length");
equal( a, 1, "Check first custom argument");
equal( b, 2, "Check second custom argument");
// We should add this back in when we want to test the order
// in which event handlers are iterated.
- //$child.bind("foo", error );
+ //$child.on("foo", error );
event = new jQuery.Event("foo");
- $child.trigger( event, [1,2,3] ).unbind();
+ $child.trigger( event, [1,2,3] ).off();
equal( event.result, "result", "Check event.result attribute");
// Will error if it bubbles
$child.triggerHandler("foo");
- $child.unbind();
- $parent.unbind().remove();
+ $child.off();
+ $parent.off().remove();
// Ensure triggerHandler doesn't molest its event object (#xxx)
event = jQuery.Event( "zowie" );
ok( "keyCode" in event, "Special 'keyCode' property exists" );
- jQuery("body").bind( "keydown", handler ).trigger( event );
+ jQuery("body").on( "keydown", handler ).trigger( event );
- jQuery("body").unbind( "keydown" );
+ jQuery("body").off( "keydown" );
});
}
});
-test(".delegate()/.undelegate()", function() {
+test(".on()/.off()", function() {
expect(65);
var submit = 0, div = 0, livea = 0, liveb = 0;
- jQuery("#body").delegate("#qunit-fixture div", "submit", function(){ submit++; return false; });
- jQuery("#body").delegate("#qunit-fixture div", "click", function(){ div++; });
- jQuery("#body").delegate("div#nothiddendiv", "click", function(){ livea++; });
- jQuery("#body").delegate("div#nothiddendivchild", "click", function(){ liveb++; });
+ jQuery("#body").on("submit", "#qunit-fixture div", function(){ submit++; return false; });
+ jQuery("#body").on("click", "#qunit-fixture div", function(){ div++; });
+ jQuery("#body").on("click", "div#nothiddendiv", function(){ livea++; });
+ jQuery("#body").on("click", "div#nothiddendivchild", function(){ liveb++; });
// Nothing should trigger on the body
jQuery("body").trigger("click");
// Make sure no other events were removed in the process
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendivchild").trigger("click");
- equal( submit, 0, "undelegate Click on inner div" );
- equal( div, 2, "undelegate Click on inner div" );
- equal( livea, 1, "undelegate Click on inner div" );
- equal( liveb, 1, "undelegate Click on inner div" );
+ equal( submit, 0, "off Click on inner div" );
+ equal( div, 2, "off Click on inner div" );
+ equal( livea, 1, "off Click on inner div" );
+ equal( liveb, 1, "off Click on inner div" );
// Now make sure that the removal works
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("#body").undelegate("div#nothiddendivchild", "click");
+ jQuery("#body").off("click", "div#nothiddendivchild");
jQuery("div#nothiddendivchild").trigger("click");
- equal( submit, 0, "undelegate Click on inner div" );
- equal( div, 2, "undelegate Click on inner div" );
- equal( livea, 1, "undelegate Click on inner div" );
- equal( liveb, 0, "undelegate Click on inner div" );
+ equal( submit, 0, "off Click on inner div" );
+ equal( div, 2, "off Click on inner div" );
+ equal( livea, 1, "off Click on inner div" );
+ equal( liveb, 0, "off Click on inner div" );
// Make sure that the click wasn't removed too early
submit = 0; div = 0; livea = 0; liveb = 0;
jQuery("div#nothiddendiv").trigger("click");
- equal( submit, 0, "undelegate Click on inner div" );
- equal( div, 1, "undelegate Click on inner div" );
- equal( livea, 1, "undelegate Click on inner div" );
- equal( liveb, 0, "undelegate Click on inner div" );
+ equal( submit, 0, "off Click on inner div" );
+ equal( div, 1, "off Click on inner div" );
+ equal( livea, 1, "off Click on inner div" );
+ equal( liveb, 0, "off Click on inner div" );
// Make sure that stopPropagation doesn't stop live events
submit = 0; div = 0; livea = 0; liveb = 0;
- jQuery("#body").delegate("div#nothiddendivchild", "click", function(e){ liveb++; e.stopPropagation(); });
+ jQuery("#body").on("click", "div#nothiddendivchild", function(e){ liveb++; e.stopPropagation(); });
jQuery("div#nothiddendivchild").trigger("click");
equal( submit, 0, "stopPropagation Click on inner div" );
equal( div, 1, "stopPropagation Click on inner div" );
event.button = 1;
jQuery("div#nothiddendiv").trigger(event);
- equal( livea, 0, "delegate secondary click" );
+ equal( livea, 0, "on secondary click" );
- jQuery("#body").undelegate("div#nothiddendivchild", "click");
- jQuery("#body").undelegate("div#nothiddendiv", "click");
- jQuery("#body").undelegate("#qunit-fixture div", "click");
- jQuery("#body").undelegate("#qunit-fixture div", "submit");
+ jQuery("#body").off("click", "div#nothiddendivchild");
+ jQuery("#body").off("click", "div#nothiddendiv");
+ jQuery("#body").off("click", "#qunit-fixture div");
+ jQuery("#body").off("submit", "#qunit-fixture div");
// Test binding with a different context
- var clicked = 0, container = jQuery("#qunit-fixture")[0];
- jQuery("#qunit-fixture").delegate("#foo", "click", function(e){ clicked++; });
+ var clicked = 0;
+ jQuery("#qunit-fixture").on("click", "#foo", function(e){ clicked++; });
jQuery("#qunit-fixture div").trigger("click");
jQuery("#foo").trigger("click");
jQuery("#qunit-fixture").trigger("click");
jQuery("body").trigger("click");
- equal( clicked, 2, "delegate with a context" );
+ equal( clicked, 2, "on with a context" );
// Test unbinding with a different context
- jQuery("#qunit-fixture").undelegate("#foo", "click");
+ jQuery("#qunit-fixture").off("click", "#foo");
jQuery("#foo").trigger("click");
- equal( clicked, 2, "undelegate with a context");
+ equal( clicked, 2, "off with a context");
// Test binding with event data
- jQuery("#body").delegate("#foo", "click", true, function(e){ equal( e.data, true, "delegate with event data" ); });
+ jQuery("#body").on("click", "#foo", true, function(e){ equal( e.data, true, "on with event data" ); });
jQuery("#foo").trigger("click");
- jQuery("#body").undelegate("#foo", "click");
+ jQuery("#body").off("click", "#foo");
// Test binding with trigger data
- jQuery("#body").delegate("#foo", "click", function(e, data){ equal( data, true, "delegate with trigger data" ); });
+ jQuery("#body").on("click", "#foo", function(e, data){ equal( data, true, "on with trigger data" ); });
jQuery("#foo").trigger("click", true);
- jQuery("#body").undelegate("#foo", "click");
+ jQuery("#body").off("click", "#foo");
// Test binding with different this object
- jQuery("#body").delegate("#foo", "click", jQuery.proxy(function(e){ equal( this["foo"], "bar", "delegate with event scope" ); }, { "foo": "bar" }));
+ jQuery("#body").on("click", "#foo", jQuery.proxy(function(e){ equal( this["foo"], "bar", "on with event scope" ); }, { "foo": "bar" }));
jQuery("#foo").trigger("click");
- jQuery("#body").undelegate("#foo", "click");
+ jQuery("#body").off("click", "#foo");
// Test binding with different this object, event data, and trigger data
- jQuery("#body").delegate("#foo", "click", true, jQuery.proxy(function(e, data){
- equal( e.data, true, "delegate with with different this object, event data, and trigger data" );
- equal( this.foo, "bar", "delegate with with different this object, event data, and trigger data" );
- equal( data, true, "delegate with with different this object, event data, and trigger data");
+ jQuery("#body").on("click", "#foo", true, jQuery.proxy(function(e, data){
+ equal( e.data, true, "on with with different this object, event data, and trigger data" );
+ equal( this.foo, "bar", "on with with different this object, event data, and trigger data" );
+ equal( data, true, "on with with different this object, event data, and trigger data");
}, { "foo": "bar" }));
jQuery("#foo").trigger("click", true);
- jQuery("#body").undelegate("#foo", "click");
+ jQuery("#body").off("click", "#foo");
// Verify that return false prevents default action
- jQuery("#body").delegate("#anchor2", "click", function(){ return false; });
+ jQuery("#body").on("click", "#anchor2", function(){ return false; });
var hash = window.location.hash;
jQuery("#anchor2").trigger("click");
equal( window.location.hash, hash, "return false worked" );
- jQuery("#body").undelegate("#anchor2", "click");
+ jQuery("#body").off("click", "#anchor2");
// Verify that .preventDefault() prevents default action
- jQuery("#body").delegate("#anchor2", "click", function(e){ e.preventDefault(); });
+ jQuery("#body").on("click", "#anchor2", function(e){ e.preventDefault(); });
hash = window.location.hash;
jQuery("#anchor2").trigger("click");
equal( window.location.hash, hash, "e.preventDefault() worked" );
- jQuery("#body").undelegate("#anchor2", "click");
+ jQuery("#body").off("click", "#anchor2");
// Test binding the same handler to multiple points
var called = 0;
function callback(){ called++; return false; }
- jQuery("#body").delegate("#nothiddendiv", "click", callback);
- jQuery("#body").delegate("#anchor2", "click", callback);
+ jQuery("#body").on("click", "#nothiddendiv", callback);
+ jQuery("#body").on("click", "#anchor2", callback);
jQuery("#nothiddendiv").trigger("click");
equal( called, 1, "Verify that only one click occurred." );
equal( called, 1, "Verify that only one click occurred." );
// Make sure that only one callback is removed
- jQuery("#body").undelegate("#anchor2", "click", callback);
+ jQuery("#body").off("click", "#anchor2", callback);
called = 0;
jQuery("#nothiddendiv").trigger("click");
// Make sure that it still works if the selector is the same,
// but the event type is different
- jQuery("#body").delegate("#nothiddendiv", "foo", callback);
+ jQuery("#body").on("foo", "#nothiddendiv", callback);
// Cleanup
- jQuery("#body").undelegate("#nothiddendiv", "click", callback);
+ jQuery("#body").off("click", "#nothiddendiv", callback);
called = 0;
jQuery("#nothiddendiv").trigger("click");
equal( called, 1, "Verify that one foo occurred." );
// Cleanup
- jQuery("#body").undelegate("#nothiddendiv", "foo", callback);
+ jQuery("#body").off("foo", "#nothiddendiv", callback);
// Make sure we don't loose the target by DOM modifications
// after the bubble already reached the liveHandler
- var livec = 0, elemDiv = jQuery("#nothiddendivchild").html("<span></span>").get(0);
+ var livec = 0;
+ jQuery("#nothiddendivchild").html("<span></span>");
- jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(""); });
- jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} });
+ jQuery("#body").on("click", "#nothiddendivchild", function(e){ jQuery("#nothiddendivchild").html(""); });
+ jQuery("#body").on("click", "#nothiddendivchild", function(e){ if(e.target) {livec++;} });
jQuery("#nothiddendiv span").trigger("click");
equal( jQuery("#nothiddendiv span").length, 0, "Verify that first handler occurred and modified the DOM." );
equal( livec, 1, "Verify that second handler occurred even with nuked target." );
// Cleanup
- jQuery("#body").undelegate("#nothiddendivchild", "click");
+ jQuery("#body").off("click", "#nothiddendivchild");
// Verify that .live() occurs and cancel bubble in the same order as
- // we would expect .bind() and .click() without delegation
+ // we would expect .on() and .click() without delegation
var lived = 0, livee = 0;
// bind one pair in one order
- jQuery("#body").delegate("span#liveSpan1 a", "click", function(){ lived++; return false; });
- jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; });
+ jQuery("#body").on("click", "span#liveSpan1 a", function(){ lived++; return false; });
+ jQuery("#body").on("click", "span#liveSpan1", function(){ livee++; });
jQuery("span#liveSpan1 a").trigger("click");
equal( lived, 1, "Verify that only one first handler occurred." );
equal( livee, 0, "Verify that second handler doesn't." );
// and one pair in inverse
- jQuery("#body").delegate("span#liveSpan2", "click", function(){ livee++; });
- jQuery("#body").delegate("span#liveSpan2 a", "click", function(){ lived++; return false; });
+ jQuery("#body").on("click", "span#liveSpan2", function(){ livee++; });
+ jQuery("#body").on("click", "span#liveSpan2 a", function(){ lived++; return false; });
lived = 0;
livee = 0;
equal( livee, 0, "Verify that second handler doesn't." );
// Cleanup
- jQuery("#body").undelegate("click");
+ jQuery("#body").off("click", "**");
// Test this, target and currentTarget are correct
- jQuery("#body").delegate("span#liveSpan1", "click", function(e){
- equal( this.id, "liveSpan1", "Check the this within a delegate handler" );
- equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a delegate handler" );
- equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a delegate handler" );
- equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" );
+ jQuery("#body").on("click", "span#liveSpan1", function(e){
+ equal( this.id, "liveSpan1", "Check the this within a on handler" );
+ equal( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a on handler" );
+ equal( e.delegateTarget, document.body, "Check the event.delegateTarget within a on handler" );
+ equal( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a on handler" );
});
jQuery("span#liveSpan1 a").trigger("click");
- jQuery("#body").undelegate("span#liveSpan1", "click");
+ jQuery("#body").off("click", "span#liveSpan1");
// Work with deep selectors
livee = 0;
function clickB(){ livee++; }
- jQuery("#body").delegate("#nothiddendiv div", "click", function(){ livee++; });
- jQuery("#body").delegate("#nothiddendiv div", "click", clickB);
- jQuery("#body").delegate("#nothiddendiv div", "mouseover", function(){ livee++; });
+ jQuery("#body").on("click", "#nothiddendiv div", function(){ livee++; });
+ jQuery("#body").on("click", "#nothiddendiv div", clickB);
+ jQuery("#body").on("mouseover", "#nothiddendiv div", function(){ livee++; });
equal( livee, 0, "No clicks, deep selector." );
jQuery("#nothiddendivchild").trigger("mouseover");
equal( livee, 1, "Mouseover, deep selector." );
- jQuery("#body").undelegate("#nothiddendiv div", "mouseover");
+ jQuery("#body").off("mouseover", "#nothiddendiv div");
livee = 0;
jQuery("#nothiddendivchild").trigger("click");
jQuery("#nothiddendivchild").trigger("mouseover");
equal( livee, 0, "Mouseover, deep selector." );
- jQuery("#body").undelegate("#nothiddendiv div", "click", clickB);
+ jQuery("#body").off("click", "#nothiddendiv div", clickB);
livee = 0;
jQuery("#nothiddendivchild").trigger("click");
equal( livee, 1, "Click, deep selector." );
- jQuery("#body").undelegate("#nothiddendiv div", "click");
+ jQuery("#body").off("click", "#nothiddendiv div");
});
test("jQuery.off using dispatched jQuery.Event", function() {
.remove();
});
-test("undelegate all bound events", function(){
+test("off all bound delegated events", function(){
expect(2);
var count = 0,
clicks = 0,
div = jQuery("#body");
- div.delegate( "div#nothiddendivchild", "click submit", function(){ count++; } );
- div.bind( "click", function(){ clicks++; } );
- div.undelegate();
+ div.on( "click submit", "div#nothiddendivchild", function(){ count++; } );
+ div.on( "click", function(){ clicks++; } );
+ div.off( undefined, "**" );
jQuery("div#nothiddendivchild").trigger("click");
jQuery("div#nothiddendivchild").trigger("submit");
div.trigger("click");
equal( clicks, 2, "Make sure delegated and directly bound event occurred." );
- div.unbind("click");
+ div.off("click");
});
-test("delegate with multiple events", function(){
+test("on with multiple delegated events", function(){
expect(1);
var count = 0;
var div = jQuery("#body");
- div.delegate("div#nothiddendivchild", "click submit", function(){ count++; });
+ div.on("click submit", "div#nothiddendivchild", function(){ count++; });
jQuery("div#nothiddendivchild").trigger("click");
jQuery("div#nothiddendivchild").trigger("submit");
equal( count, 2, "Make sure both the click and submit were triggered." );
- jQuery("#body").undelegate();
+ jQuery("#body").off( undefined, "**" );
});
-test("delegate with change", function(){
+test("delegated on with change", function(){
expect(8);
var selectChange = 0, checkboxChange = 0;
var select = jQuery("select[name='S1']");
- jQuery("#body").delegate("select[name='S1']", "change", function() {
+ jQuery("#body").on("change", "select[name='S1']", function() {
selectChange++;
});
checkboxFunction = function(){
checkboxChange++;
};
- jQuery("#body").delegate("#check2", "change", checkboxFunction);
+ jQuery("#body").on("change", "#check2", checkboxFunction);
// test click on select
// test blur/focus on text
var text = jQuery("#name"), textChange = 0, oldTextVal = text.val();
- jQuery("#body").delegate("#name", "change", function() {
+ jQuery("#body").on("change", "#name", function() {
textChange++;
});
equal( textChange, 1, "Change on text input." );
text.val(oldTextVal);
- jQuery("#body").undelegate("#name", "change");
+ jQuery("#body").off("change", "#name");
// test blur/focus on password
var password = jQuery("#name"), passwordChange = 0, oldPasswordVal = password.val();
- jQuery("#body").delegate("#name", "change", function() {
+ jQuery("#body").on("change", "#name", function() {
passwordChange++;
});
equal( passwordChange, 1, "Change on password input." );
password.val(oldPasswordVal);
- jQuery("#body").undelegate("#name", "change");
+ jQuery("#body").off("change", "#name");
// make sure die works
// die all changes
selectChange = 0;
- jQuery("#body").undelegate("select[name='S1']", "change");
+ jQuery("#body").off("change", "select[name='S1']");
select[0].selectedIndex = select[0].selectedIndex ? 0 : 1;
select.trigger("change");
equal( selectChange, 0, "Die on click works." );
equal( selectChange, 0, "Die on keyup works." );
// die specific checkbox
- jQuery("#body").undelegate("#check2", "change", checkboxFunction);
+ jQuery("#body").off("change", "#check2", checkboxFunction);
checkbox.trigger("change");
equal( checkboxChange, 1, "Die on checkbox." );
});
-test("delegate with submit", function() {
+test("delegated on with submit", function() {
expect( 2 );
var count1 = 0, count2 = 0;
- jQuery("#body").delegate("#testForm", "submit", function(ev) {
+ jQuery("#body").on("submit", "#testForm", function(ev) {
count1++;
ev.preventDefault();
});
- jQuery(document).delegate("body", "submit", function(ev) {
+ jQuery(document).on("submit", "body", function(ev) {
count2++;
ev.preventDefault();
});
equal( count1, 1, "Verify form submit." );
equal( count2, 1, "Verify body submit." );
- jQuery("#body").undelegate();
- jQuery(document).undelegate();
+ jQuery("#body").off( undefined, "**" );
+ jQuery(document).off( undefined, "**" );
});
-test("undelegate() with only namespaces", function() {
+test("delegated off() with only namespaces", function() {
expect(2);
var $delegate = jQuery("#liveHandlerOrder"),
count = 0;
- $delegate.delegate("a", "click.ns", function(e) {
+ $delegate.on("click.ns", "a", function(e) {
count++;
});
equal( count, 1, "delegated click.ns");
- $delegate.undelegate(".ns");
+ $delegate.off( ".ns", "**" );
jQuery("a", $delegate).eq(1).trigger("click.ns");
- equal( count, 1, "no more .ns after undelegate");
+ equal( count, 1, "no more .ns after off");
});
test("Non DOM element events", function() {
var o = {};
- jQuery(o).bind("nonelementobj", function(e) {
+ jQuery(o).on("nonelementobj", function(e) {
ok( true, "Event on non-DOM object triggered" );
});
// focus the element so DOM focus won't fire
input[0].focus();
- jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
+ jQuery( "body" ).on( "focusin.focusinBubblesTest", function(){
equal( 1, order++, "focusin on the body second" );
});
- input.bind( "focusin.focusinBubblesTest", function(){
+ input.on( "focusin.focusinBubblesTest", function(){
equal( 0, order++, "focusin on the element first" );
});
input.trigger( "focus" );
input.remove();
- jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
+ jQuery( "body" ).off( "focusin.focusinBubblesTest" );
});
test("custom events with colons (#3533, #8272)", function() {
$onandoff.remove();
});
-test("special bind/delegate name mapping", function() {
+test("special on name mapping", function() {
expect( 7 );
jQuery.event.special["slap"] = {
saved = jQuery.event.fixHooks.click;
// Ensure the property doesn't exist
- $fixture.bind( "click", function( event ) {
+ $fixture.on( "click", function( event ) {
ok( !("blurrinessLevel" in event), "event.blurrinessLevel does not exist" );
});
fireNative( $fixture[0], "click" );
- $fixture.unbind( "click" );
+ $fixture.off( "click" );
jQuery.event.fixHooks.click = {
filter: function( event, originalEvent ) {
};
// Trigger a native click and ensure the property is set
- $fixture.bind( "click", function( event ) {
+ $fixture.on( "click", function( event ) {
equal( event.blurrinessLevel, 42, "event.blurrinessLevel was set" );
});
fireNative( $fixture[0], "click" );
delete jQuery.event.fixHooks.click;
- $fixture.unbind( "click" ).remove();
+ $fixture.off( "click" ).remove();
jQuery.event.fixHooks.click = saved;
});
// Bind to the ready event in every possible way.
jQuery(makeHandler("a"));
jQuery(document).ready(makeHandler("b"));
- jQuery(document).bind("ready.readytest", makeHandler("c"));
+ jQuery(document).on("ready.readytest", makeHandler("c"));
// Do it twice, just to be sure.
jQuery(makeHandler("d"));
jQuery(document).ready(makeHandler("e"));
- jQuery(document).bind("ready.readytest", makeHandler("f"));
+ jQuery(document).on("ready.readytest", makeHandler("f"));
noEarlyExecution = order.length === 0;
ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
// Ensure execution order.
- deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in bind-order, but those bound with jQuery(document).bind( 'ready', fn ) will always execute last");
+ deepEqual(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in on-order, but those bound with jQuery(document).on( 'ready', fn ) will always execute last");
// Ensure handler argument is correct.
equal(args["a"], jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
equal(args["b"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
- ok(args["c"] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
+ ok(args["c"] instanceof jQuery.Event, "Argument passed to fn in jQuery(document).on( 'ready', fn ) should be an event object");
order = [];
equal(order.pop(), "h", "Event handler should execute immediately");
equal(args["h"], jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
- jQuery(document).bind("ready.readytest", makeHandler("never"));
+ jQuery(document).on("ready.readytest", makeHandler("never"));
equal(order.length, 0, "Event handler should never execute since DOM ready has already passed");
// Cleanup.
- jQuery(document).unbind("ready.readytest");
+ jQuery(document).off("ready.readytest");
});
})();
jQuery.removeEvent = wrapperRemoveEvent ;
- $fixture.bind( "change", function( event ) {});
- $fixture.unbind( "change" );
+ $fixture.on( "change", function( event ) {});
+ $fixture.off( "change" );
$fixture.remove();