I want to change the background color after clicking
This is my HTML code
...
I would add the id to your <td>
tag and change the name of function for a better understanding.
function changeBgColor() {
var tableData = document.getElementById('meun');
tableData.style.backgroundColor = '#EFF2F7';
}
<td id='meun' class="meun" onclick="changeBgColor()">...</td>
http://jsfiddle.net/ThiefMaster/3ZmCh/16/
You need to pass this
as an argument and use proper JavaScript in the handler method:
function getclick(elem) {
elem.style.backgroundColor = '#EFF2F7';
}
<script language="JavaScript">
<!--
function changeBGC(color){
document.bgColor = color;
}
//-->
</script>
<a href="#" onClick="javascript:changeBGC('#000099')">Click Blue</a>
Your getclick() function should look like this:
function getclick(el)
{
el.style.backgroundColor='#888888';
}
In js, styles look a little different
and in your td, do
<td onclick="getclick(this)">
Here's the code in jQuery:
$("td").click(function() {
$(this).css("background-color","#ABCDEF");
});