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

121
Views
If ID contains Javascript

I have following JS

    var slider = new Slider("#testslider", {
        tooltip: 'always'
    });

To style my bootstrap slider by ID. I want to style every slider in that area so I tried to put them all in one DIV like:

<div id="testslider">
//all sliders
</div>

That will only style the first slider.

I tried [id^="testslider"] and named every slider in this scheme: testslider1, testslider2 etc.

But that will only style the first slider. Now with document.querySelectorAll([id^="testslider"]); I could select all IDs but I can't figure out how to put that into

var slider = new Slider("#testslider", {
    tooltip: 'always'
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Now with document.querySelectorAll([id^="testslider"]); I could select all IDs but I can't figure out how to put that into

var slider = new Slider("#testslider", {
  tooltip: 'always'
});

I suppose you absolutely need the id to instanciate the tooltip plugin...
Use a loop to go through each elements, get it's specific id to instancitate the slider:

const allSliders = Array.from(document.querySelectorAll('[id^="testslider"]'));
console.log("allSliders length:", allSliders.length)

allSliders.forEach((element) => {
  console.log("id for tooltip:", "#"+element.id)  // To check if the right ids are used
  new Slider("#"+element.id, {  // The specific id is used here
    tooltip: 'always'
  });
})
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!