• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

121
Vistas
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.

almost 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

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>

almost 3 years ago · Juan Pablo Isaza Denunciar

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

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda