How Do You Use AddEventListener?

How do you call a function in addEventListener?

Either call the function in an anonymous function (like your first example) or alter the function to return a function.

function message_me(m_text){ alert(m_text) } second.

addEventListener(‘click’, function() { message_me(‘shazam’); } );.

What is the difference between addEventListener and Onclick?

addEventListener can add multiple events, whereas with onclick this cannot be done. onclick can be added as an HTML attribute, whereas an addEventListener can only be added within