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,

TheBoubou
  • 19,487
  • 54
  • 148
  • 236

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
  • 384,651
  • 66
  • 527
  • 531
1

.trigger()

You can use .trigger('click');

PSR
  • 39,804
  • 41
  • 111
  • 151
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,351
  • 3
  • 13
  • 28