From 5d033dba02fc1ffe1398cdaf0e9d402fc75e13f0 Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Mon, 21 Apr 2008 20:39:17 +0000 Subject: [PATCH] Trigger onclick handlers of links --- src/event.js | 4 ++-- test/unit/event.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index 927beda4e..d0cacf6b5 100644 --- a/src/event.js +++ b/src/event.js @@ -203,8 +203,8 @@ jQuery.event = { if ( jQuery.isFunction( jQuery.data(elem, "handle") ) ) val = jQuery.data(elem, "handle").apply( elem, data ); - // Handle triggering native .onfoo handlers - if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) + // Handle triggering native .onfoo handlers (and on links since we don't call .click() for links) + if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) val = false; // Extra functions don't get the custom event object diff --git a/test/unit/event.js b/test/unit/event.js index ba29ab7ec..0ec0f5966 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -113,7 +113,7 @@ test("bind(), namespaced events, cloned events", function() { }); test("click()", function() { - expect(4); + expect(5); $('
  • Change location
  • ').prependTo('#firstUL').find('a').bind('click', function() { var close = $('spanx', this); // same with $(this).find('span'); ok( close.length == 0, "Context element does not exist, length must be zero" ); @@ -131,6 +131,13 @@ test("click()", function() { }; $('#firstp').click(); ok( counter == 1, "Check that click, triggers onclick event handler also" ); + + var clickCounter = 0; + $('#simon1')[0].onclick = function(event) { + clickCounter++; + }; + $('#simon1').click(); + ok( clickCounter == 1, "Check that click, triggers onclick event handler on an a tag also" ); }); test("unbind(event)", function() {