I am facing an issue with a function that contains another function within it. The main function has an onclick event, and I want it to call the inner function. However, when I click on the element, it gives an error saying that the function is not defined. The onclick event is part of a for loop. Here's the code snippet:
function changeColor(){
function textBackgroundColor(color){
//updateText("<font color='"+color+"'>"+selectedText()+"</font>");
alert("a");
}
var tableContent;
var colors=["#000000","#FF0000","#00FF00","#0000FF","#FFFF00","#00FFFF","#FF00FF","#666666"];
var names=["Black","Red","Green","Blue","Yellow","Turquoise","Magenta","Gray"];
for(var i=0;i<colors.length;i++){
tableContent=tableContent+"<tr><td><div **onclick='textBackgroundColor(this.style.background)'** style='cursor:pointer;width:28px;height:28px;background:"+colors[i]+";margin-left:17px;'></div></td><td>"+names[i]+"</td><td>"+colors[i]+"</td></tr>";
}
tableContent="<center><table id='colorTable'><tr><th>Preview </th><th>Color Name </th><th>Color Code</th></tr>"+tableContent+"</table></center>";
document.getElementById("sidebar").innerHTML=tableContent.replace("undefined","");
}