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

111
Views
JavaScript, change the href attribute of multiple a elements that have the same class

I want to change (or control...) my <a> href with JavaScript. Here is my HTML structure:

<a class="google" href="#">LINK ONE</a>
<a class="google" href="#">LINK TWO</a>

And here my JavaScript code:

document.querySelectorAll("a.google").href = "https://google.com"

If I use querySelector(".google") it change the link, but just one of theme. If I use querySelectorAll(".google") or ("a.google") it doesn't change anything.

Can anyone help me?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.querySelectorAll returns an array of elements. For this to work, and it was a good idea to think about it, you can do like so :

const links = document.querySelectorAll("a.google");
links.forEach(link => link.href = "https://google.com");
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!