Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
HTML Button wont do anything when clicked

I am making my website and I have my header buttons wont do anything. The main problems are on lines 12 to 15. Here is the code:

<!DOCTYPE html>
<html>
    <head>

        <script src="https://kit.fontawesome.com/6feb1dab38.js" crossorigin="anonymous"></script>
        <link rel="stylesheet" href="resources/css/stylesheet.css">
        <title>Home</title>
    </head>
    <header>
    </header>
    <body>
        <div class="context">
            <button class="headerButton" type="button">About Me</button>
            <button class="headerButton" type="button">Links</button>
            <button class="headerButton" type="button" onclick="window.location.href='Clicked/Works'; console.log('it worked')">Works</button>
            <br>
            <script src="resources/js/app.js"></script>
        </div>
    
    
    <div class="area" >
                <ul class="circles">
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                        <li></li>
                </ul>
        </div >
        <script src="resources/js/app.js"></script>
    </body>
</html>

I think it has something to do with the buttons being inside the context . Please let me know any answers you may have.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are assigning a value to location.href, causing the page to redirect.

Change your button to:

 <button class="headerButton" type="button" onclick="console.log('it worked')">Works</button>

about 4 years ago · Juan Pablo Isaza Report

0

It is not really clear what you are trying to achieve. If you want to hook an event handler to the button then you need to write the following in your js code:

HTML:

<button id="my-button">
  CLICK ME!
</button>

JS:

const button = document.querySelector('#my-button');
button.addEventListener('click', () => {
    button.innerHTML = 'YOU CLICKED ME!';
    // ... or perform whatever action you would like...
})

Here's an example code of this:

https://stackblitz.com/edit/js-kt8cab?file=index.js

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!