I am learning JavaScript on Udemy and there is a task to write a code that displays content when a "view more" button is clicked.
I can't understand how this
works in the display content code and how JavaScript understands what the variable t
is.
I found a solution in the QA section, but I am not sure how it works.
Apparently, the for i++
loop code is necessary so that the code works for each button in a tab.
Questions:
- How does
this
work here and why is it necessary? - How does JavaScript understand what
t
is?
let desctiptionTab = document.querySelectorAll('.description-btn');
for (let i = 0; i < desctiptionTab.length; i++) {
desctiptionTab[i].addEventListener('click', function() {
Modal(this);
});
}
function Modal(t) {
overlay.style.display = 'block';
t.classList.add('more-splash');
document.body.style.overflow = 'hidden';
};