cgp25 cgp25 - 1 month ago 8
HTML Question

HTML - new page with html section on click

I have an html page with several classes, one of which I would like to access upon clicking a button. Is this possible? This is my current code:

<div class = "sign-in">
<button id="myButton">Click to log in</button>
<script type="text/javascript">
document.getElementById("myButton").addEventListener("click", myFunction, true);
function myFunction() {
alert ("Hello World!");
}
</script>
</div>


But instead of having a pop-up window saying "Hello World", I would like the button to navigate to a new page, which is already constructed in the same html file, as seen below:

<div class="tabs">

<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Scanner</label>

<div class="content">
Click here for your scanner
</div>
</div>

</div>


Just now sure how to link the two. Thank you in advance!

Answer

You could add window.location.href to redirect your page

For instance

<div class = "sign-in">
        <button id="myButton">Click to log in</button>
        <script type="text/javascript">
        document.getElementById("myButton").addEventListener("click", myFunction, true);
        function myFunction() {
            window.location.href="mypage.html";
        }
        </script>
    </div>