Here I created a jquery function that gets css-color and creates element with background of css-color: Edit my jsFiddle
html
<div ID="wrapper">
<div ID="addColor">
<input type="text" ID="hex">
<div ID="color">Your color</div>
<button ID="add">Add color</button>
<div CLASS="clear"></div> <!-- Clear float -->
</div>
<div ID="wrapGallery">
<h1>My Color Gallery</h1>
<ul ID="gallery"></ul>
</div>
</div>
js/jquery
$(function() {
//float left with some margin
$('#addColor')
.children().not('#add, .clear').css({
'float':'left',
'margin-right': '5px'
});
//Showing color on keyup
$('#hex').keyup(function() {
var hexCode = $(this).val();
$('#color').css('background-color', hexCode);
if ( hexCode !== '') {
$('#color').text('');
}else{
$('#color').text('Your color');
}
});
//Adding colors
$gallery = $('#gallery');
$('#add').click(function() {
var storedHex = $('#hex').val();
//check if empty
if (storedHex == '') {
alert('Enter something');
}
else {
//adding li
$("<li>").css('background-color', storedHex)
.hover(
function () {
$(this).text(storedHex);
},
function () {
$(this).text('');
})
.appendTo($gallery);
}
});
});
The only thing I need to do is to save the created elements permanently in the file, so I can access whenever I want. I have no idea how to do that.
Read up on JQuery Ajax function and also read about JSON objects.
With AJAX and JQuery you can easily send a JSON object to your server like so:
A JSON file may look something like this:
You could generate a JSON string representing a JSON object and send it to a PHP file with the Ajax function (as above).
In PHP you would do this to obtain the object:
You could also convert an array in PHP to a JSON object using the PHP json_encode function.
Read more:
http://www.w3schools.com/json/default.asp
http://php.net/manual/en/function.json-decode.php
http://php.net/manual/en/function.json-encode.php
http://api.jquery.com/jQuery.ajax/