When creating a table and adding a row click event with the purpose of retrieving the value of the first td, the following code is used:
function bclick(){
var result=[];
SAPget.step4QueryTable(function(data){
var tbody=document.querySelector("tbody");
for(var i=0;i<data.length;i++)
{
var tr=document.createElement("tr");
tbody.appendChild(tr);
var td=document.createElement("td");
tr.appendChild(td);
td.innerHTML=data[i].code;
var td1=document.createElement("td");
tr.appendChild(td1);
if (data[i].name!="")
{
td1.innerHTML=data[i].name;
}
else
{
td1.innerHTML="";
}
tr.onclick=function fun(){
alert(this.children("td:first"));
}
}
}
)
}
Despite efforts, the code always returns "undefined" when tested. Further debugging in IE reveals that the children have a length of 2 but the value is empty. Could someone please help identify the issue? Thank you.