views:

56

answers:

2

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.

+1  A: 

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.

Rex M
the OP's `.trigger('click');` did not work... what's the difference with your `$('#thebutton').click();` then?
Reigel
@Reigel there is no difference... I'm just explaining what it actually does to hopefully help explain the seemingly-confusing behaviour.
Rex M
How does jquery ui attach the active classes? Shouldn't it also work by triggering?
Mark
+1  A: 

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.

demo

html

<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>​

jQuery

$(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');
    });
});
Reigel
Sorry, forgot to mention that my button is a radio. I guess that's what makes the difference. http://jsfiddle.net/Qs6cX/2/
Mark
it's still the same... Well, I guess you are not that clear on what you are trying to achieve...
Reigel
@Reigel well if you click on a radio it clearly looks like the radio was selected, that does not happen by triggering in js.
Mark
Actually made a mistake in my jsfiddle sorry: http://jsfiddle.net/Qs6cX/3/
Mark