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

85
Views
Troubleshooting a Javascript class' click-event function

I have a JS 'shuffle' function that I am trying to execute every time a user clicks on the shuffleBtn class in my HTML. I am using classes over IDs because I have multiple shuffleBtn instances.

I'm not too familiar with JS/jQuery and can't see why my syntax is broken. Any pointers appreciated!

<script>

window.onload = function() {
  $('.shuffleBtn').on('click', function(){
  var refs = $(".ref");
    for(var i = 0; i < refs.length; i++){
        var target = Math.floor(Math.random() * refs.length -1) + 1;
        var target2 = Math.floor(Math.random() * refs.length -1) +1;
        refs.eq(target).before(refs.eq(target2));
    }
 };
 };
 
</script>
about 4 years ago · Juan Pablo Isaza
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!