Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!