Auto-click button element on page load using jQuery

If I wanted to auto-click a button element on page load, how would I go about this using jQuery?

The button html is

<button class="md-trigger" id="modal" data-modal="modal"></button>

Any help on this topic would be greatly appreciated! Thanks in advance!


You would simply use jQuery like so...

<script>
jQuery(function(){
   jQuery('#modal').click();
});
</script>

Use the click function to auto-click the #modal button


JavaScript Pure:

<script type="text/javascript">
document.getElementById("modal").click();
</script>

JQuery:

<script type="text/javascript">
$(document).ready(function(){
    $("#modal").trigger('click'); 
});
</script>

or

<script type="text/javascript">
$(document).ready(function(){
    $("#modal").click(); 
});
</script>

Use the following code

$("#modal").trigger('click');

I tried the following ways in first jQuery, then JavaScript:

jQuery:

 window.location.href = $(".contact").attr('href');
 $('.contactformone').trigger('click');  

This is the best way in JavaScript:

 document.getElementById("id").click();