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
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.
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.
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 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.
Does this not work?
<script>
jQuery(function(){
jQuery('#featuretoggle').click();
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With