Anu

Anu

  • 1.4k
  • 301
  • 10.9k

Need to set the color of an element using a variable with javascript

Oct 12 2020 5:11 AM
Hi,
 
Please help me to use a variable inside  e.cellElement.css("backgroundColor", "var(---" + result.value + ")"); using javascript. I am able to get the color value in the variable "result.value". But its not changing the color using the variable name. I am able to change the color, if I am writing the color name directly inside .css().
 
Below is the code which I am using. 
 
function gettingcolour(e) {
if (e.column.dataField === "undefined") {
}
else
{
$.ajax({
type: "POST",
url: "/Home1/getcolurdetails", // the URL of the controller action method
data: { data: e.column.dataField },
/* data: "{'colname' :' " + e.column.dataField + "'}",*/ // optional data
success: function (result) {
e.cellElement.css("backgroundColor", "var(---" + result.value + ")");
},
error: function (req, status, error) {
alert('error')
}
});
}
}
 
Thanks
Hanusha 
 
 

Answers (4)