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
Use querySelector to get select based on two conditions, one being a prefix

So I am trying to select a div based on two conditions, one being a prefix.

So if I have

<div class="bob delay-10"></div>
<div class="joe delay-20"></div>

I want to have

function getdelay (classname) {
    let delayselect = document.querySelector("*[class='"+classname+"'], *[class*='delay-']");
return delayselect;
}
getdelay("joe");

should return <div class="joe delay-20"></div>

Currently the way it is working is it is selecting OR not AND.

How can I fix this?

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

0

Use an actual class selector (.) for the fixed class name part.

let delayselect = document.querySelector(`.${classname}[class*='delay-']`);

The backticks ("template literals") allow for simpler inclusion of expressions in strings.

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!