0

I have this code :

<button type="button" 
    data-toggle="modal" id="testing" 
    class="btn btn-icon btn-primary glyphicons circle_ok" 
    data-target="#myModal"><i></i>
</button>

I'd like simulate a click via a function executed when the page is loaded.

How can I do this ?

Thanks,

3
  • 1
    have you tried .trigger('click')? Commented Jun 6, 2013 at 5:57
  • or $('button#testing').click(); Commented Jun 6, 2013 at 5:58
  • hope simulate doesn't mean the visual change takes place while clicking Commented Jun 6, 2013 at 5:59

3 Answers 3

3

Use the shorthand method .click()

$('your-button-selector').click()

or .trigger()

$('your-button-selector').trigger('click')

To simulate a click event, it will run all registered click event handlers, but may/may not trigger the default action

Sign up to request clarification or add additional context in comments.

Comments

1

.trigger()

You can use .trigger('click');

Comments

0

You can add following code to your page

<script type="text/javascript">

$(function(){

  $('button#testing').click()

});

</script>

Here is a working demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.