Reputation: 33571
button.trigger('click');
doesn't seem to work.
There's also no trigger method in the docs.
Is the only way to set the classes manually?
Thanks.
Edit:
Oh actually not specific enough in asking, sorry. My button is a radio.
Upvotes: 2
Views: 963
Reputation: 728
Indeed jQuery need some time to attach the event handler with the button..
so with this:
window.setTimeout( function(){
jQuery("#thebutton").trigger("click");
}, 10 );
you should be fine ;-)
Upvotes: 0
Reputation: 1
Just refer to the actual element instead of the jQuery object.
So the syntax would be: $('#thebutton')[0].click();
.
Upvotes: -1
Reputation: 65254
That should work... There is no no trigger method in the docs of jQuery UI simply because it's still the same on how you do it normally on jQuery. I mean the following codes can demonstrate it to you.. see also demo.
<div class="demo">
<button>A button element</button>
<input type="submit" value="A submit button"/>
<a href="#">An anchor</a>
</div><!-- End demo -->
<button id="trigger">Trigger Submit button click</button>
$(function() {
// make button()
$("button, input:submit, a", ".demo").button().click(function(){
alert('from button() : I was triggered!');
});
// add click handler..
$('input:submit').click(function(){
alert('a submit button being triggered');
});
// prevent default operation of an anchor
$("a", ".demo").click(function() { return false; });
// trigger click on submit button
$('#trigger').click(function(){
$('input:submit').trigger('click');
});
});
Upvotes: 2
Reputation: 144112
You can call $('#thebutton').click();
but it is important to note that does not simulate a browser-level click; it only invokes any jQuery-assigned click handlers for that button. Anything added outside of the jQuery sandbox will be ignored.
Upvotes: 1