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

229
Views
How do I make a conditional with hasClass that prints a text depending on the content of another div tag?

For example if have:

<div>New York</div>

So I would like to print another div like this:

<div>Free Delivery</div>

How would I do that using JS?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

add id to element :

<div id="country">New York</div>

and then

let country = $('#country')

setInterval(()=>{
   if(country.text()=='New York'){
      // Your code
      // exemple 
      alert('Congratulations ! We Ship for Free for New York 
            Customers');
   }
},3000)

i hope it was useful

about 4 years ago · Santiago Gelvez Report

0

you can do this with simple js condtion:

add a class/id to to the element <div id="country">New York</div>

and in your script:

window.onload = () => {
  const country = document.querySelector('#country');
  const printdiv = '<div>Free Delivery</div>';

  if(country && country.textContent.trim() == 'New York'){
  document.querySelector('#country').insertAdjacentHTML('afterend',printdiv)
  }
}
about 4 years ago · Santiago Gelvez 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!