Rob
Rob

Reputation: 305

Trigger event listener

I am currently making a website with the use of simpleCart(js)(open jQuery Shopping Cart).

In html this fires the event to empty the shopping cart:

<a class="simpleCart_empty" href="javascript:;"></a>

I would like to combine this event with a few other action so I try to fire it on my commend without actually clicking on the link.

The source has this:

 me.addEventToArray( getElementsByClassName('simpleCart_empty') , simpleCart.empty , "click" );

Does anyone no how to trigger it in jQuery? Or how to find how to do that? A regular:

 $(".simpleCart_empty").trigger('click');

doesn't work, and seems like a wrong workaround.

The code:

$(simpleCart.empty).trigger('click');

Does the trick.

Upvotes: 1

Views: 2893

Answers (2)

Sergio Campam&#225;
Sergio Campam&#225;

Reputation: 746

Try using the bind() function of jQuery

 $('.simpleCart_empty').bind('click', function() {
     alert('Should empty cart');
 });

Just replace the alert with the actions you want to execute

Upvotes: 0

Keith.Abramo
Keith.Abramo

Reputation: 6955

Did you try

$(".simpleCart_empty").click();

Upvotes: 1

Related Questions