Florius
Florius

Reputation: 125

I can't trigger the 'click' event on jQuery

So, I have a listener:

$('div#Team div.wrap ul').on('click', 'li:not(.current)', function(){
...
}

and

$('div#Team div.wrap ul li#' + hash.split("/")[1]).click();

but it won't trigger, I checked is the selector was garbing the correct LI, and it is grabbing the correct element. I tried manually copy and paste'ing the code "..." onto where I call the ".click()" that isn't working (with some minor adjustments for $(this)) and id too works, but that means I have duplicated code, which I don't want.

Thank you in advance.

Upvotes: 2

Views: 947

Answers (1)

Royi Namir
Royi Namir

Reputation: 148644

jQuery Uses arrays.

click will work on the dom object.

while trigger('click') will work on the jquery object.

$('div#Team div.wrap ul li#' + hash.split("/")[1])[0].click();

or

$('div#Team div.wrap ul li#' + hash.split("/")[1]).trigger('click');

Upvotes: 2

Related Questions