Javascript Library.
Commands 0 |
---|
Attach a function executes when event triggered.
_z(selector).on("click", function);
Returns: Object _z(selector)
To unbind an event: Unbind event
_z(selector).trigger("click");
Returns: Object _z(selector)
_z(selector).un("click", [function]);
Returns: Object _z(selector)
<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.