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

105
Views
Substitution of content by js

I have a problem with JS code. Well, the text of the first link changes. The second one stays the same and I would like to change too. How to do it correctly?

HTML:

<h4 class="comments-title">Text1</h4>
        <a rel="nofollow" class="comment-reply-link" href="#comment-25416">reply</a>    

        <a rel="nofollow" class="comment-reply-link" href="#comment-2">reply</a>

JS:

    function podmien(klasa, tekst) {
    document.querySelector(klasa).innerHTML = tekst;
}
document.addEventListener('DOMContentLoaded', function() {
podmien('.comments-title', 'Com');
podmien('.comment-reply-link', 'Answer');
Document.getElementsByClassName
});

https://jsfiddle.net/tomaszpl/8s43wao5/28/

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

0

querySelector will only select the first element. What you need is querySelectorAll to select all elements.

function podmienAll(klasa, tekst) {
  document.querySelectorAll(klasa).forEach(v => {
    v.innerHTML = tekst;
  });
}

document.addEventListener('DOMContentLoaded', function() {
  podmienAll('.comments-title', 'Com');
  podmienAll('.comment-reply-link', 'Answer');
});
<h4 class="comments-title">Text1</h4>
<a rel="nofollow" class="comment-reply-link" href="#comment-25416">reply</a>
<a rel="nofollow" class="comment-reply-link" href="#comment-2">reply</a>

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!