# Problems with jQuery

**URL:** <https://forum.freecodecamp.org/t/problems-with-jquery/118693>\
**Category:** General\
**Created:** [May 22, 2017, 10:06pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery/118693 "2017-05-22T22:06:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yayoamigo](https://avatars.discourse-cdn.com/v4/letter/y/6de8d8/32.png) [@yayoamigo](https://forum.freecodecamp.org/u/yayoamigo)\
**Post date:** [May 22, 2017, 10:06pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery/118693/1 "2017-05-22T22:06:27Z")

</div>

I am trying to change the color of my HTML background by using Jquery every time i click a button. This is my code $(document).ready(function(){  
var colors = [’#16a085’, ‘#27ae60’, ‘#2c3e50’, ‘#f39c12’, ‘#e74c3c’, ‘#9b59b6’, ‘#FB6964’, ‘#342224’, “#472E32”, “#BDBB99”, “#77B1A9”, “#73A857”];  
var color = Math.floor(Math.random() \* colors.length);

$(".btn").click(function() {

```
$("body").css("background-color", color);

```

});  
})

---

<div class="post-metadata">

**Author:** ![pedrogabrielbg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pedrogabrielbg/32/54671_2.png) [@pedrogabrielbg](https://forum.freecodecamp.org/u/pedrogabrielbg)\
**Post date:** [May 22, 2017, 10:25pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery/118693/2 "2017-05-22T22:25:36Z")

</div>

Try this:

```auto
$(document).ready(function(){
var colors = ['#16a085', '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", "#73A857"];
var color = "";

$(".btn").click(function() {
color = colors[Math.floor(Math.random() * colors.length)];

$("body").css("background-color", color);

});
})

```

Also make sure you have a link to jquery in your html code.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:54pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery/118693/4 "2021-01-17T20:54:21Z")

</div>

Closed on January 17, 2021, 8:54pm UTC


