Trigger a button on page load

与世无争的帅哥 提交于 2019-11-30 09:44:11

Does this not work?

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

That's the easiest way:

<script>
    $(function() {
        $("#featuretoggle").trigger("click");
    });
</script>

You can trigger a click event manually with jQuery:

$('#featuretoggle').click();

To do this when the page loads:

$(document).ready(function() {
    $('#featuretoggle').click();
});

I imagine you'll want this to be the last thing to happen when loading the page, so make sure it's the last line to be executed within $(document).ready().

See this example:

<a href="#" id="someButton">Foo</a>
<script type="text/javascript">
    $(document).ready(function() {
        // bind the click event
        $('#someButton').click(function() {
            alert('baz');
        });

        // trigger the click event
        $('#someButton').click();
    });
</script>

What you want is can be achived by using setTimeout() function.

$(document).ready(function() {
    setTimeout(function() {
        $("a#<?php echo $custom_jq_settings['toggle']; ?>").trigger('click');
    },10);
});

This will work for you surely...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!