UnderZ

Javascript Library.

Bind or trigger an event on an element.

Attach a function executes when event triggered.


Bind click event

_z(selector).on("click", function);

Returns: Object _z(selector)

To unbind an event: Unbind event


Trigger click event

_z(selector).trigger("click");

Returns: Object _z(selector)


Unbind an event

_z(selector).un("click", [function]);

Returns: Object _z(selector)


Examples

<button id="button">Change Title</button>
<button id="buttonBind">Bind event</button>
<button id="buttonUnbind">Unbind event</button>

<script>
// bind click event by element id
_z("#buttonBind").on("click", function () { 

	// bind click event.
	_z("#button").on("click", function () { 
		// set title as the element value
		document.title = _z(this).text();
	});
	
});


// unbind click event by element id
_z("#buttonUnbind").on("click", function () { 

	// unbind click event.
	_z("#button").un("click");
	
});

// bind click event by element tag name
_z("button").on("click", function () { 
	// set title as the element value
	document.title = _z(this).text();
});


// trigger click event
_z("#button").trigger("click"); // Trigger click event
</script>

Recommended: bind events in .ready() to execute the event when the document is fully loaded.