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

254
Views
Randomizing locations of css with JavaScript

It should randomize the location of a black circle when pressed but I can’t figure out why it isn’t working.

function myFunction1(button) {
  var xPosition = math.floor(math.random() * 101) + '%';
  button.style.top = xPosition;
  var yPosition = math.floor(math.random() * 101) + '%';
  button.style.left = yPosition;
}
.circle {
  width: 100px;
  height: 100px;
  background-color: red;
  border-radius: 50%;
}

.black {
  background-color: black;
}
<button type="button" class="black circle" onclick="myFunction1(this)"></button>

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

0

Try this:

Change math... to Math..

And add this to css:

.circle {
  ...
  position: fixed;
}

Like this:

function myFunction1(button) {
  var xPosition = Math.floor(Math.random() * 101) + '%';
  button.style.top = xPosition;
  var yPosition = Math.floor(Math.random() * 101) + '%';
  button.style.left = yPosition;
}
.circle {
  width: 100px;
  height: 100px;
  background-color: red;
  border-radius: 50%;
  position: fixed;
}

.black {
  background-color: black;
}
<button type="button" class="black circle" onclick="myFunction1(this)"></button>

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!