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

180
Visualizações
HTML anchor tag have href first then onclick()

In an anchor tag with both href and onClick, is it possible to have the href first go to the link then execute the onClick()?

For example, I want this anchor tag to first go to the link and then call the highlightButton function.

<a
  class="page-link" 
  href="?page={{step.previous_page_number}}" 
  onClick="highlightButton();"
  aria-label="Previous"
>Previous</a>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Nope. You can, however, check and validate the parameter page from the URL when the document is ready then execute the highlightButton() function.

Example:

HTML

<a class="page-link" href="?page={{step.previous_page_number}}" aria label="Previous">Previous</a>

javaScript

document.addEventListener("DOMContentLoaded", function() {
    const params = new URLSearchParams(location.search);
    const page = params.get("page");

    // Example Validation
    if (page != "" || page != null) {
        highlightButton();
    }

    function highlightButton() {
        // Code goes here
    }
});
about 4 years ago · Juan Pablo Isaza Relatório

0

No, You cannot do that, by opening a new link, the last page wont work at the background but if you want to use a specific function in the next page, just write the function and call it at the top of your script tag!

Like this :

<script>
    highlightButton()
    function highlightButton() {
        // your code 
    }
</script>
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