Closing the internal function:
document.addEventListener("DOMContentLoaded", function (){
var txta = document.getElementsByTagName('textarea');
for (var i = 0; i < txta.length; i++){
var earse = txta[i].value;
console.log(earse);
(function(earse){
txta[i].addEventListener('focus', function(e){
if (e.target.value === earse) {
e.target.value = "";
e.target.addEventListener('blur', function(e){
if (e.target.value === "") {
e.target.value = earse;
}
}, false);
}
}, false);
})(earse);
console.log(txta[i]);
};
}, false);
http://jsfiddle.net/WjV8n/
For comments: you need a closed vibrating bruise inside the loop. Because every step you change this variable.
source
share