const targetName = document.querySelectorAll('.name');
for(let i = 0; i < targetName.length; i++) {
targetName[i].onClick = function() {
for(let j = 0; j < arr.length; j++) {
if(targetName[i].textContent === arr[j].firstName + ' ' + arr[j].lastName) {
return printRole(arr[j]);
}
}
}
}
//제대로 작동하지 않음
const targetName = document.querySelectorAll('.name');
targetName.forEach(function(el) {
el.addEventListener('click', function() {
for(let j = 0; j < arr.length; j++) {
if(el.textContent === arr[j].firstName + ' ' + arr[j].lastName) {
return printRole(arr[j]);
}
}
})
})
//제대로 작동함
관계가 있을 가능성이 있는 단서
document.querySelectorAll로 만들어진 NodeList는 유사배열이다.
'알아볼 것' 카테고리의 다른 글
aws 관련해서 찾아볼 내용 (1) | 2021.01.26 |
---|---|
함수 선언식이 호이스팅에 영향을 받는다면 왜 사용할까? (0) | 2020.09.28 |
i++과 i=+(혹은 i+=?)의 차이 (0) | 2020.09.25 |
객체지향에서 this의 의미 (0) | 2020.09.25 |