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

170
Visualizações
How can I select link and then add onclick event to change other elements styling

I want to know how can I select first,second,third,etc. link from nav. So that I can add onclick event function that changes appearance of Div. Also I have goTo links like index.html#div1. The idea is to click link and the link to navigates us to the div and change it appearance(## Heading ## box-shadow or change background color ), but temporary. You can check some code over here: "https://jsfiddle.net/malle/gwq924fu/1/"

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Have you tried using the JavaScript querySelectorAll() for the links?

You could use something like:

const links = document.querySelectorAll("a");

And to modify its CSS:

links[0].style.backgroundColor = "red";

But all the a elements should have the onClick defined to your function, so you could use if statements to validate what element you would like to modify.

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