# The Events


Introduction:

Events and JavaScript are closely related — can you imagine writing scripts for web pages that don’t respond to user interaction? That means that as soon as JavaScript appeared, events did. Early event handlers were written inline, like this:

                  
<a href="/" onclick="alert('Hello World!')">        
                  
                

Siga offers you an simplified and powerful events to generate a web page

Bind an event to an element:

                  
Siga.events.add(element, 'click', function() {
   console.log('Clicked');
 });        
                  
                

You can Remove an event from an element. Example:

                  
Siga.events.add(element, 'click', callback);         
                  
                

You can also Fires an event. Example:

                  
SIga.events.fire(element, 'click');
         
                  
                

Add a 'DOM ready' callback. Example:

                  
Siga.events.ready(function() {
   // The DOM is ready
 });       
                  
                

Events can be chained with DOM calls. For example:

                  
Siga('p').bind('click', function(e) {
    alert('ouch');
  });        
                  
                

A generic event manager, based on Node's EventEmitter. For example:

                  
var EventEmitter = Siga.events.Emitter,
      emitter = new EventEmitter();

  emitter.on('testFired', function() {
    assert.ok(true);
  });

  emitter.emit('testFired')       
                  
                

Find a single item. For example:

                  
 var a = [1, 2, 3, 4, 5, 6, 7, 8];
 Siga.enumerable.detect(a, function(n) {
   return n === 3;
 });

 => 3      
                  
                

The DOM ready event handlers can also be set with:

                  
Siga.ready(function() { });

// Or just by passing a function to Siga()

Siga(function() {} );