how to click the button using javascript code example

Example 1: how to open a new html page on button click in javascript

<button id="myButton" class="float-left submit-button" >Home</button>

<script type="text/javascript">
    document.getElementById("myButton").onclick = function () {
        location.href = "www.yoursite.com";
    };
</script>

Example 2: javascript click button by id

var button = document.getElementById("button");
button.click();

Example 3: javascript click

const element = document.querySelector('element');
element.click();

Example 4: how to make a button in javascript

<button id="btn">button</button>