This is the structure of HTML. I have to add an event listener when user click on div with className "next_button". I try to add an event listener by using prototype.
<div id="horizontal_carousel2">
<div class="previous_button"></div>
<div class="container" >
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<div id="spinner2" style="display: block;"><br /></div>
</div>
<div class="next_button"></div>
</div>
This is the script which executes on load:
<script type="text/javascript">
Event.observe(window, 'load', function() {
$$("#horizontal_carousel .next_button").first().observe( 'click',tezt());
});
function tezt()
{
alert("calling me");
}
</script>
The problem is "calling me" alerted as the window load completes. I am not able to figure out the problem. What am I missing? I have to show alert message when user click on next button.. T
The second parameter to observe should be a reference to a function. When you passed tezt() as the second parameter, you executed tezt() and passed its result to observe.