Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 3

Rifqi Fahmi
Rifqi Fahmi
23,164 Points

Make the padding random colour

hola amigo!!

hmm I want to improve my gallery website. I plan to make the padding of the image to become more colourful with random colour. The padding colour of each image is different to the other. then every we refresh the page the padding show up with random colour again.

I want to ask how we do that bye changing the css and selecting the padding of each image with javascrip?

1 Answer

Jonathan Romine
Jonathan Romine
9,344 Points

Something like this

function get_random_color() { var color = ""; for(var i = 0; i < 3; i++) { var sub = Math.floor(Math.random() * 256).toString(16); color += (sub.length == 1 ? "0" + sub : sub); } return "#" + color; }