I want to send the background color of an element to a function using javascript for example:
<td style="background-color:#ff0000" onClick="getColor()"></td>
Could anyone please give me a pointer as to what I have to do in the getColor() function?
change this to:
<td style="background-color:#ff0000" onClick="getColor(this)"></td>
And this would be the javasctipt:
getColor(elem){
alert(elem.style.backgroundColor);
}
If jQuery is ok:
<td style="background-color:#ff0000" onClick="getColor(this)"></td>
<script>
function getColor(element) {
var bgColor = $(element).css('background-color');
// ... do something with bgColor here...
}
</script>
Modify the call to send the object as param. Like this-
<td style="background-color:#ff0000" onClick="getColor(this)"></td>
And the function would be-
function getColor(obj){
var bgColor = obj.style.backgroundColor;
alert(var);
}