Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a 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 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

like image 543
Jamison Avatar asked Jan 12 '12 18:01

Jamison


People also ask

How do you click a button to load a page?

Example 1 :- Using window. You can use it in one link of code . By default,the open() method opens a new tab. Learn how to open new html page on button click in same window. By passing the _self parameter, the URL will replace the current page.

How do I automatically click a button on a Web page?

Open the console by right-clicking the element you wish to automate clicks for and selecting the inspect option. You should see a lot of highlighted lines of HyperText Markup Language (HTML). Now the button should be visible in code on the side of your browser.

How do I trigger a button click script?

In the Elements tray, click Form Elements and drag a Submit button onto your page. In the Button Settings tab of the Properties panel, set the button mode to Trigger. Go to the Actions and Events tab of the Properties panel, and select Add New Action. Click Done.

How to trigger button click event in jQuery on page load?

How to trigger click event on page load in jQuery? Yeah, you can use a click event called onLoad() . Just use the setTimeout() method in jquery. It will call a click function without clicking it.


1 Answers

Does this not work?

<script>
    jQuery(function(){
      jQuery('#featuretoggle').click();
    });
</script>
like image 93
aknosis Avatar answered Oct 29 '22 14:10

aknosis