[jQuery] Re: No reaction with $('a').click(), OK with dispatchEvent(...)

2009-11-20 Thread Jon
Hi,

At the moment I'm not so interested in the right/smart way to write an
a tag. It's more interesting to me to see what the jQuery click()
function can and cannot do, and it could also be interesting to know
why it fails where my clickAt(...) works.
I have now extended my test page
http://folk.uio.no/jkleiser/test/jq-test.html
with two new a variants: one (#a2) new-school that uses 'onclick',
and one (#a3) that links to this Google Groups page. With the latter I
observe the same difference as with #a1: my clickAt($('#a3')[0])
works, but $('#a3').click() doesn't. Bug or feature?

/Jon

On Nov 19, 11:36 pm, Olaf Bosch olaf.bo...@t-online.de wrote:
 Jon schrieb:

  Hi,

  I have an element like this: a id=a1 href=javascript:doSomething
  ();#a1/a
  However, when I do this: $('#a1').click(); ... then my doSomething()
  do not get called. Why?

 Try the jQuery-Way:

 a id=a1 href=##a1/a

 $('#a1').click( function() {
          doSomething();
          return false;
          });

 --
 Viele Gr e, Olaf

 ---
 olaf.bo...@t-online.dehttp://olaf-bosch.de/http://ohorn.info/http://www.akitafreund.de/
 ---


Re: [jQuery] Re: No reaction with $('a').click(), OK with dispatchEvent(...)

2009-11-20 Thread Olaf Bosch

Jon schrieb:


and one (#a3) that links to this Google Groups page. With the latter I
observe the same difference as with #a1: my clickAt($('#a3')[0])
works, but $('#a3').click() doesn't. Bug or feature?


Sorry I can't follow you. I added this to Firebug on your Testpage:

$('#a3').click( function() {
  return false;
  });

And then Click on #a3 and nothing

--
Viele Grüße, Olaf

---
olaf.bo...@t-online.de
http://olaf-bosch.de/
http://ohorn.info/
http://www.akitafreund.de/
---


[jQuery] Re: No reaction with $('a').click(), OK with dispatchEvent(...)

2009-11-20 Thread Jon
Hi,

I'm not quite sure what you try to show me with that $('#a3').click
(...stuff...) below, but I can tell you what I just found out: The
difference I've mentioned between my clickAt($('#a1')[0]) and $
('#a1').click(), and also with #a3, occurs in Safari and Opera, but in
Firefox (3.0.3 and 3.5.5) my clickAt(...) does no more than $
(...).click(). In IE7 my clickAt(...) just gives me an [object Error].
What a mess!

/Jon

On Nov 20, 11:18 am, Olaf Bosch olaf.bo...@t-online.de wrote:
 Jon schrieb:

  and one (#a3) that links to this Google Groups page. With the latter I
  observe the same difference as with #a1: my clickAt($('#a3')[0])
  works, but $('#a3').click() doesn't. Bug or feature?

 Sorry I can't follow you. I added this to Firebug on your Testpage:

 $('#a3').click( function() {
            return false;
            });

 And then Click on #a3 and nothing

 --
 Viele Gr e, Olaf

 ---
 olaf.bo...@t-online.dehttp://olaf-bosch.de/http://ohorn.info/http://www.akitafreund.de/
 ---


[jQuery] Re: No reaction with $('a').click(), OK with dispatchEvent(...)

2009-11-20 Thread KeeganWatkins
 At the moment I'm not so interested in the right/smart way to write an
 a tag. It's more interesting to me to see what the jQuery click()
 function can and cannot do

ok, then read the source. we're trying to offer solutions to the
problem, but if you just want some info on what jQuery's click method
is capable of, it's defined on lines #2590 through #2663 in version
1.3.2.
or you can read the docs:
http://docs.jquery.com/Events/trigger
NOTE: Most of the event shortcut methods (click, hover, focus, etc)
use jQuery,event.trigger() under the hood.

On Nov 20, 5:47 am, Jon jon.klei...@usit.uio.no wrote:
 Hi,

 I'm not quite sure what you try to show me with that $('#a3').click
 (...stuff...) below, but I can tell you what I just found out: The
 difference I've mentioned between my clickAt($('#a1')[0]) and $
 ('#a1').click(), and also with #a3, occurs in Safari and Opera, but in
 Firefox (3.0.3 and 3.5.5) my clickAt(...) does no more than $
 (...).click(). In IE7 my clickAt(...) just gives me an [object Error].
 What a mess!

 /Jon

 On Nov 20, 11:18 am, Olaf Bosch olaf.bo...@t-online.de wrote:

  Jon schrieb:

   and one (#a3) that links to this Google Groups page. With the latter I
   observe the same difference as with #a1: my clickAt($('#a3')[0])
   works, but $('#a3').click() doesn't. Bug or feature?

  Sorry I can't follow you. I added this to Firebug on your Testpage:

  $('#a3').click( function() {
             return false;
             });

  And then Click on #a3 and nothing

  --
  Viele Gr e, Olaf

  ---
  olaf.bo...@t-online.dehttp://olaf-bosch.de/http://ohorn.info/http://www.akitafreund.de/
  ---


[jQuery] Re: No reaction with $('a').click(), OK with dispatchEvent(...)

2009-11-19 Thread KeeganWatkins
if you have to keep your JavaScript inline, you should use the onclick
attribute instead of using the javascript: pseudo-protocol. it was
never fully standardized, and is a lingering piece of old-school
JavaScript usage. so for your example above, use:
a id=a1 onclick=doSomething();#a1/a

an even better solution (as you are already using jQuery), would be to
use the built-in binding jQuery provides, which allows you to a.) keep
your JS out of the markup, and b.) have more than one handler if you
need to:
$(function() {
$(#a1).click(function() {
// handle event here
});
});

On Nov 19, 8:21 am, Jon jon.klei...@usit.uio.no wrote:
 Hi,

 I have an element like this: a id=a1 href=javascript:doSomething
 ();#a1/a
 However, when I do this: $('#a1').click(); ... then my doSomething()
 do not get called. Why?

 If I make my own click function, like this:
 function clickAt(targetElement) {
         var evt = document.createEvent(HTMLEvents);
         evt.initEvent(click, true, true);
         return targetElement.dispatchEvent(evt);

 }

 ... and call it this way: clickAt($('#a1')[0]); ... then my doSomething
 () do get called.

 If you like, you can try it out here: http://folk.uio.no/jkleiser/
 test/jq-test.html

 /Jon