Javascript pass parameter to eventListener function whilst in loop
This code will pass the last value created by the loop the eventListener
function, I need the value at the time the eventListener was created to be
attached.
window.onload = function() {
var el = document.getElementsByClassName('modify');
for (var i = 0; i < el.length; i++) {
var getId=el[i].id.split("_");
document.getElementById("modify_y_"+getId[2]).addEventListener('mouseover',
function() {
document.getElementById("modify_x_"+getId[2]).style.borderBottom =
'#e6665 solid 3px';
}, false);
}
}
No comments:
Post a Comment