javascript autoclick not working in php (wordpress)

There is a post type on my theme where a meta box is at the bottom of default body section. There is a “Add New” button at that metabox, when the button is being clicked a new section appears. I want the hidden section always being visible. I tried the javascript click() function so that the button becomes auto-clicked.

These are the theme original codes:

Read More
echo '<a href="javascript:void(0);" class="option-tree-social-links-add option-tree-ui-button button button-primary right hug-right" title="' . __( 'Add New', 'option-tree' ) . '">' . __( 'Add New', 'option-tree' ) . '</a> ';

I tried the following codes but its not working:

echo '<a href="javascript:void(0);" class="option-tree-list-item-add option-tree-ui-button button button-primary right hug-right" title="' . __( 'Add New', 'option-tree' ) . '">' . __( 'Add New', 'option-tree' ) . '</a> <script>document.getElementsByClassName("option-tree-list-item-add option-tree-ui-button button button-primary right hug-right")[0].click(); </script>';

Need help!

Related posts

Leave a Reply

1 comment