I have a div I want, when the user clicks on this div, the background color of the div should only be displayed in the warning field using jquery?
div
try it
<script type="text/javascript"> $(document).ready(function(){ $("div").click(function(){ var $c=$(this).css("background-color"); alert($c); }); }); </script>
$('div').click(function() { alert($(this).css('background-color')); });
jsFiddle .
You can get the color as follows:
$('div#test').css('background-color'); // returns RGB
and display it after clicking as follows:
$('div#test').click(function(){ alert($(this).css('background-color')); });
See the script: http://jsfiddle.net/xWkDW/1/
#divBack{ background-color:#00FFCC; } <div id="divBack">click to Get my background</div> $('#divBack').click(function() { alert($(this).css('background-color')); });
I created a bin for you, please check this link http://codebins.com/codes/home/4ldqpc1