I have added 2 buttons in my page and I have added the default button click code using javascript but it is not working.
This is my HTML code:
<button class="tablink" onclick="openPage('inside', this, '#0077c0')" id="defaultOpen">Inside</button> <button class="tablink" style="left:40px;" onclick="openPage('outside', this, '#0077c0')" >Outside</button>
This is JS code added in functions.php
:
function wp_head_custom_mm(){ ?> // Get the element with id="defaultOpen" and click on it document.getElementById("defaultOpen").click(); </script> <?php } add_action('wp_head', 'wp_head_custom_mm');
But it is not working, my default button is not clicked.
Error:
Uncaught TypeError: Cannot read property 'click' of null
I want to button with id defaultOpen
should be clicked when the website opens.
Any help is much appreciated.