DEV Community

Discussion on: [Solved] 2020: Pure Vanilla Javascript Smooth Scroll to Element on anchor tag click #id

Collapse
 
kazirezaurrahman profile image
Kazi-Rezaur-Rahman

document
.querySelectorAll('.nav__item a[href^="#"]')
.forEach(trigger => {
trigger.onclick = function(e) {
e.preventDefault();

"Can you please explain what do you mean by 'trigger' in here?"

Collapse
 
arvindrk profile image
Arvind Ram Singh Kishore

Trigger is the respective DOM Node that is being looped over using the forEach. Also, a onClick handler is being attached to each anchor tag using the same variable 'trigger'