Reputation: 77
there is a lot of similiar questions, but I have a problem that I want to trigger event which is already set. The code on the page is:
<a class="btn-medium btn-primary TradeCurrencyModalBtn">Start</a>
I used Visual Event plugin and it showed this:
As you can see, the button has his own function set.
But my code does nothing:
$( document ).ready(function() {
$("a.btn-medium btn-primary TradeCurrencyModalBtn").trigger("click");
});
When I click on trigger event (in the picture), it triggers perfectly. This is what I tried (none of them working):
$("a.btn-medium btn-primary TradeCurrencyModalBtn")[0].trigger("click");
$("a.btn-medium btn-primary TradeCurrencyModalBtn")[0].click();
$("a.btn-medium btn-primary TradeCurrencyModalBtn").click();
I even tried deleting all other elements, still not triggering from my code. Any ideas? I have implemented the latest JQuery.
Upvotes: 0
Views: 79
Reputation: 62488
your selector is wrong.
do like this:
$("a.btn-medium.btn-primary.TradeCurrencyModalBtn").trigger("click");
// tirgger click for anchor tag which has class btn-medium btn-primary TradeCurrencyModalBtn
as you are trying to fire click for anchor which has all these classes.
Upvotes: 3