If I understand correctly you want to change the CSS style of an element by clicking an item in a ul
list. Am I right?
HTML:
<div class="results" style="background-color:Red;">
</div>
<ul class="colors-list">
<li>Red</li>
<li>Blue</li>
<li>#ffee99</li>
</ul>
jquery
$('.colors-list li').click(function(e){
var color = $(this).text();
$('.results').css('background-color',color);
});
Note that jquery can use addClass
, removeClass
and toggleClass
if you want to use classes rather than inline styling. This means that you can do something like that:
$('.results').addClass('selected');
And define the 'selected' styling in the CSS.
Working example: http://jsfiddle.net/uuJmP/