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,

Kris-I
  • 18,550
  • 52
  • 145
  • 228

3 Answers3

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

Arun P Johny
  • 376,738
  • 64
  • 519
  • 520
1

.trigger()

You can use .trigger('click');

PSR
  • 38,073
  • 36
  • 106
  • 149
0

You can add following code to your page

<script type="text/javascript">

$(function(){

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

});

</script>

Here is a working demo

Himal
  • 1,343
  • 3
  • 13
  • 27