Creating Color Gallery

71 views Asked by At

I am trying to make Colors' Gallery, but I cannot achieve it. Here is what I've done so far.
I want to try, when the user clicks button, li appended to ul and this is where the mess starts. I thought after I append li, the background-color would've applied to li itself but it instead applied to ul. Could you help me pls, cuz I am newbie and also don't blame me for my English if I have mistakes. English is my third language, trying to explain as hard as I can!

2

There are 2 answers

3
arunes On BEST ANSWER

I changed your code check it out http://jsfiddle.net/8USqU/5/

This part is looking wrong.

$('#gallery').append('<li></li>').css('background', storedHex);  

I changed to

$("<li>").css('background-color', storedHex).appendTo($('#gallery'));

Actually you can use background-color instead of background. Because background selector can take lots of property, but all you need is background-color

0
Ohgodwhy On

You need to simply change the order of operations.

Instead of targeting the Gallery, adding the element, and trying to change the css.

We'll create the element, target the Element's CSS, then append that element to #gallery.

Have a look at the jsfiddle below to see the change in action.

http://jsfiddle.net/8USqU/4/