").click(function() { jQuery("#

Run button on page load

I have this function

$("a#<?php echo $custom_jq_settings['toggle']; ?>").click(function() {
        jQuery("#<?php echo $custom_jq_settings['div']; ?>").slideToggle(400);
        jQuery("#featurepagination").toggle();
        jQuery("#featuretitlewrapper").toggle();
        return false;
    });

And this is the button that I want to call when the page loads

<a href="#" id="featuretoggle" onclick="changeText('<?php if (is_front_page()) {?>Show<?php } else { ?>Show<?php } ?> Features');"><?php if (is_front_page()) {?>Hide<?php } else { ?>Hide<?php } ?> Features</a>

I would like to launch this button when the page loads so that it starts to open, but then the slide / closes

+5
source share
4 answers

Does this work?

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

This is the easiest way:

$(function() {
    $("#featuretoggle").trigger("click");
});
+5
source

click jQuery:

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

:

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

, , , , $(document).ready().

See an 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>
+1
source

What you want can be achieved with the setTimeout () function.

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

This will work for you ...

0
source

All Articles