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

167
Visualizações
Se hace clic en un botón de configuración/se activa cuando se abre/actualiza la página

Tengo un pequeño sistema en el que si hago clic en un botón, cambia el color del botón en el que se hizo clic y si hago clic en el otro botón, cambia su color y vuelve a configurar el botón en el que se hizo clic anteriormente a su color original.

Todo lo que quiero es tener uno de los botones configurado como activo (hacer clic) cuando la página se abre/actualiza. Preferiblemente, el inicio de sesión establecido como predeterminado hizo clic.

Gracias de antemano :)

HTML:

 <div class="login-or-register-container"> <button class="button-categories">LOGIN</button> <button class="button-categories">REGISTER</button> </div>

CSS:

 .login-or-register-container { display: flex; } button.button-categories:hover { border-bottom-width: 1px; border-bottom-color: #1100ff; } button.button-categories { font-size: 12px; display: block; width: 100px; height: 40px; color: #fff; background-color: #555; border: solid; border-radius: 0px; border-width: 1px; border-color: #999; text-align: center; font-weight: 1000; } button.button-categories.active { border-bottom-width: 2px; border-bottom-color: #1100ff; padding-top: 1px; color: #1100ff; }

JavaScript:

 // Get all the buttons into a node list let buttons = document.querySelectorAll(".button-categories"); // Set an event handler on the document so that when // any element is clicked, the event will bubble up to it document.addEventListener("click", function(evt){ // Check to see if it was a button that was clicked if(evt.target.classList.contains("button-categories")){ // Loop over all the buttons & remove the active class buttons.forEach(function(button){ button.classList.remove("active"); }); // Make the clicked button have the active class evt.target.classList.add("active"); } });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Si desea que un botón esté activo de forma predeterminada en la carga de la página, simplemente agregue la clase active a ese botón. Me gusta:

 // Get all the buttons into a node list let buttons = document.querySelectorAll(".button-categories"); // Set an event handler on the document so that when // any element is clicked, the event will bubble up to it document.addEventListener("click", function (evt) { // Check to see if it was a button that was clicked if (evt.target.classList.contains("button-categories")) { // Loop over all the buttons & remove the active class buttons.forEach(function (button) { button.classList.remove("active"); }); // Make the clicked button have the active class evt.target.classList.add("active"); } });
 .login-or-register-container { display: flex; } button.button-categories:hover { border-bottom-width: 1px; border-bottom-color: #1100ff; } button.button-categories { font-size: 12px; display: block; width: 100px; height: 40px; color: #fff; background-color: #555; border: solid; border-radius: 0px; border-width: 1px; border-color: #999; text-align: center; font-weight: 1000; } button.button-categories.active { border-bottom-width: 2px; border-bottom-color: #1100ff; padding-top: 1px; color: #1100ff; }
 <div class="login-or-register-container"> <button class="button-categories active">LOGIN</button> <button class="button-categories">REGISTER</button> </div>

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