I have a function which has another function in it. There is an onclick event in main function and I want it to call the inner function. However when I click the element, it says that the function is not defined. The onclick event is in a for loop. Here is the code:
function renk(){
function metinRenginiDegistir(boya){
//seciliMetinDegistir("<font color='"+boya+"'>"+seciliMetin()+"</font>");
alert("a");
}
var sagic;
var renkler=new Array("#000000","#FF0000","#00FF00","#0000FF","#FFFF00","#00FFFF","#FF00FF","#666666");
var adlar=new Array("Siyah","Kırmızı","Yeşil","Mavi","Sarı","Turkuaz","Magenta","Gri");
for(i=0;i<renkler.length;i++){
sagic=sagic+"<tr><td><div **onclick='metinRenginiDegistir(this.style.background)'** style='cursor:pointer;width:28px;height:28px;background:"+renkler[i]+";margin-left:17px;'></div></td><td>"+adlar[i]+"</td><td>"+renkler[i]+"</td></tr>";
}
sagic="<center><table id='renklerinTablosu'><tr><th>Önizleme </th><th>Renk Adı </th><th>Renk Kodu</th></tr>"+sagic+"</table></center>";
sag.innerHTML=sagic.replace("undefined","");
//document.getElementById("renklerinTablosu").getElementsByTagName("div").onclick=function(){alert("a");}
// onclick='metinRenginiDegistir(this.style.background)'
}
metinRenginiDegistir()inside ofrenk(). That's the problem.<div onclick='metinRenginiDegistir()'>expects it to be in the GLOBAL scope, on the same level asrenk.