UnderZ

Javascript Library.

Bind or trigger a click event on an element.

Execute a function when an element is clicked. or trigger click event for an element.

Bind click event

_z(selector).click(function);

Returns: Object _z(selector)

This method is a shortcut for _z(selector).on( “click”, function).

To unbind click event: Unbind click event

Trigger click event

_z(selector).click();

Returns: Object _z(selector)

Unbind click event

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

Returns: Object _z(selector)

Examples

<button id="button">Show Message & Change Title</button>
<button class="btnCTitle">Change Title</button>
<button class="btnUBEvent">Unbind "Change Title" event</button>

<script>
// bind click event by element id
_z("#button").click(function () { 
	alert("Button clicked!");
});

// bind click event by element tag - this will bind the event with all elements with "button" tag.
_z("button").click(function () { 
// set title as clicked button text
	document.title = _z(this).text();
});

// unbind click event by element class.
_z(".btnUBEvent").click(function () {
	_z(".btnCTitle").un("click");
});


// trigger click event
_z(".btnCTitle").click(); // change document title to 'Change Title'
_z("#button").click(); // alert 'Button clicked!' and change document title to 'Show Message & Change Title'
_z(".btnUBEvent").click(); // change document title to 'Unbind "Change Title" event' and unbind click event on .btnCTitle button
</script>

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