Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda