Re: [jQuery] triggering an event

2006-10-24 Thread Dave Methvin

> Can I force the click event to fire manually?

To trigger an event you can use...wait for it...trigger().  :-)

$("foo").trigger("click");

Or you can call click with no arguments:

$("foo").click();

As with a real click, the "this" will be pointing to the element. I'm not
sure about the details of the first (event) argument in these cases.
However, you can tell a real click from a fake click by passing trigger some
arguments:

$("foo").trigger("click", ["other", "stuff", "here"]);

$(".foo").click(function (e, p1, p2) {
if ( p2 == "stuff" )
alert("I was triggered, not clicked.");
else
alert("Finally, an honest click.");
});
 
So is this some sort of van den Hoven family reunion around here?  :-)


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] triggering an event

2006-10-24 Thread Michael Geary
> I was wondering having done:
> 
> $(".foo").click(function (e) {alert ("foo");});
> 
> Can I force the click event to fire manually, or do I resort to
> 
> var x = function (e) {alert ("foo");}
> $("#foo").click(x);
> ele = $("#foo").get(0)
> x.call( ele, {target:ele});

You can use either of these (they do the same thing):

  $("#foo").click();

  $("#foo").trigger("click");

-Mike


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] triggering an event

2006-10-24 Thread Klaus Hartl
Adam van den Hoven schrieb:
> I was wondering having done:
> 
> $(".foo").click(function (e) {alert ("foo");});
> 
> Can I force the click event to fire manually, or do I resort to
> 
> var x = function (e) {alert ("foo");}
> $("#foo").click(x);
> ele = $("#foo").get(0)
> x.call( ele, {target:ele});


Hi Adam, fire an event manually like that:

$(".foo").click();



-- Klaus


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] triggering an event

2006-10-24 Thread Webunity | Gilles van den Hoven
Adam van den Hoven wrote:
> Can I force the click event to fire manually, or do I resort to
>   
I think you can do this with the "apply" call, although i am unsure how ;)

P.s. nice surname ;)

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] triggering an event

2006-10-24 Thread Adam van den Hoven
I was wondering having done:

$(".foo").click(function (e) {alert ("foo");});

Can I force the click event to fire manually, or do I resort to

var x = function (e) {alert ("foo");}
$("#foo").click(x);
ele = $("#foo").get(0)
x.call( ele, {target:ele});


Adam

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/