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

151
Views
How to target specific span tag in HTML using JS

Hi I have an HTML with several HTML and only a couple of span tags that I want to be fading.

I have selected all the spans:

const spans = document.querySelectorAll("span");
const animation = function () {
  for (let span of spans) span.classList.toggle("fade");
};
setInterval(animation, 2400);

Now I only want to target these 2 spans inside div

<div class="animated">
  Hey, I'm<br>
  <span
    class="color-primary mt-5 fade" 
    id="animated-name" 
    style="margin-top: 20px;"
  >
    Name Name
  </span>
  <span 
    class="color-primary mt-5" 
    id="animated-text" 
    style="margin-top: 20px;"
  >
    Text Text 
    <br> 
    Text & Text
  </span>
</div>

My question is how to target only these 2 span tags to toggle fade?

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

0

why not use document.querySelectorAll('div.animated > span')?

about 4 years ago · Juan Pablo Isaza Report

0

querySelectorAll('div.className span')

Or

querySelectorAll('span')[0] //Array span length 
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!