Auto-click button element on page load using jQuery

后端 未结 5 1739
轮回少年
轮回少年 2020-11-30 02:33

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

The button html is

相关标签:
5条回答
  • 2020-11-30 03:05

    Use the following code

    $("#modal").trigger('click');
    
    0 讨论(0)
  • 2020-11-30 03:07

    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>
    
    0 讨论(0)
  • 2020-11-30 03:07

    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();
    
    0 讨论(0)
  • 2020-11-30 03:09

    You would simply use jQuery like so...

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

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

    0 讨论(0)
  • 2020-11-30 03:15

    We should rather use Javascript.

        <button href="images/car.jpg" id="myButton">
            Here is the Button to be clicked
        </button>
    
    
        <script>
    
            $(document).ready(function(){
                document.getElementById("myButton").click();
            });
    
        </script>
    
    0 讨论(0)
提交回复
热议问题