I am trying to make a button, which when clicked show an other html document. But, I have no idea how to do it.
Asked
Active
Viewed 4,100 times
1
-
What have you tried till now – Deepak Kumar Apr 08 '19 at 06:31
-
Are you looking for an HTML Button that works like a link ? Something like https://www.w3docs.com/snippets/html/how-to-create-an-html-button-that-acts-like-a-link.html – Mebin Joe Apr 08 '19 at 06:32
-
Are you trying to submit a form? Or simply you want to redirect to another page on button click? – Deepak Kumar Apr 08 '19 at 06:32
1 Answers
3
Just add an onclick event to the button:
<button onclick="location.href = 'anotherfile.html';" id="myButton" class="float-left submit-button" >Home</button>
or you should do like that:
<button id="myButton" class="float-left submit-button" >Home</button>
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "anotherfile.html";
};
</script>
More Suggestions:
<a href='anotherfile.html'>Click here</a>

Sajid Ijaz
- 172
- 1
- 1
- 8