Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Learning JS Reply To: Learning JS

#184155
Alen
Participant

First and most importantly, how does the JS know to run when a button is clicked, there is no trigger in the HTML.

This line stores the target in the variable comments


var comments = document.getElementById('comments');

Then later,


comments.addEventListener('click',replybox_onClick);

Event listener is attached to listen to any clicks, then it just runs the replybox_onClick function.

Hope that helps,
-Alen

http://codepen.io/anon/pen/xawed