Trigger a button on page load

Jamison picture Jamison · Jan 12, 2012 · Viewed 40k times · Source

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 I want to trigger on page load

<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 trigger that button when the page loads so that it starts open but then slides/closes

Answer

aknosis picture aknosis · Jan 12, 2012

Does this not work?

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