30
rated 0 times
[
34]
[
4]
/ answers: 1 / hits: 57525
/ 11 Years ago, tue, april 30, 2013, 12:00:00
So we have a page:
<span id='container'>
<a href='#' id='first'>First Link</a>
<a href='#' id='second'>Second Link</a>
</span>
And want to add some click events:
first.addEventListener('click', function(){alert('sup!');})
Works like a charm! However, when you make the second argument an external function:
function message_me(m_text){
alert(m_text)
}
second.addEventListener('click', message_me('shazam'))
It calls the function immediately. How can I stop this? So annoying!
Here's a live demo: http://jsfiddle.net/ey7pB/1/
More From » addeventlistener