PDA

View Full Version : what is this here ?



BubikolRamios
11-11-2012, 05:22 PM
Obviously 'this' is mText object
But why it does not work if I replace
this.title
with:
arr[i]
or
mText.title
? (otherobject on click gets allways the vallue of arr[0])


//do - it loops through arreay of values
var mText = d.createElement("div");
mText.title = arr[i];
mText.onclick = function()
{
otherobject.title = this.title;
};
mContainer.appendChild(mText);
//loop


Hope this makes sence.

felgall
11-11-2012, 10:36 PM
this in that code should refer to the div that you created four lines earlier. So this.title will refer to the arr[1] value that you assigned to it three lines earlier but which will no longer be directly accessible when the onclick code runs.