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

116
Views
How do I connect this script to one of my buttons?

<button class="ordercolor" onclick="ordercolor()">Order Color</button> This is the button on HTML

var color = 
  ["#222f3e", "#dd260e", "#0ae196c", "#0ae127", "#0a7ce1", "#a60ae1", "#808000", "#00FF00", "#00FFFF", "#008080", "#FF5733"];
  var i = 0;
  addEventListener("click",
  function () {
  i = i < color.length ? ++i : 0;
  document.querySelector("body").style.background = color[i];

This is the script on Java.

That script applies on every button I got on HTML and I want it specific in one button. Can you help me apply it to the specific button ? Or maybe you have another script for changing colors in order on click, like green after red after blue (always the same) ?

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

0

You need to name the function. If you are using onclick you do not need to use the event listener. Like this:

<button class="ordercolor" onclick="ordercolor()">Order Color</button>
<script>
var color = ["#222f3e", "#dd260e", "#0ae196c", "#0ae127", "#0a7ce1", "#a60ae1", "#808000", "#00FF00", "#00FFFF", "#008080", "#FF5733"];
var i = 0;
function ordercolor() {
i = i < color.length ? ++i : 0;
document.querySelector("body").style.background = color[i];
}
</script>
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!