Demo
Code
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#sampleTable div").click(function(){
$("#color").html($(this).css("background-color"));
});
});
</script>
</head>
<body>
<table id="sampleTable">
<tr>
<td><div style="width:100px;height:100px;background:#ff0000"></div></td>
<td><div style="width:100px;height:100px;background:#00FF00"></div></td>
<td><div style="width:100px;height:100px;background:#0000FF"></div></td>
</tr>
</table>
<p id="color">Click on any box</p>
</body>
</html>
Click on any box
Code
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#sampleTable div").click(function(){
$("#color").html($(this).css("background-color"));
});
});
</script>
</head>
<body>
<table id="sampleTable">
<tr>
<td><div style="width:100px;height:100px;background:#ff0000"></div></td>
<td><div style="width:100px;height:100px;background:#00FF00"></div></td>
<td><div style="width:100px;height:100px;background:#0000FF"></div></td>
</tr>
</table>
<p id="color">Click on any box</p>
</body>
</html>
Comments
Post a Comment