Tuesday, 22 March 2011

Creating our own functions in jquery

The basis of creating a our own jQuery function is actually quite simple. The following is an example to create function:

The structure required to extend the jQuery.fn object and create our own function is…
jQuery.fn.firstFunction = function () {
return this.each (function () {
alert (this.id);
});
}
You’d now be able to call your function as you normally would call any other jquery function
$('#test').firstFunction();
This would display a “nice” alert box showing the element id.

No comments:

Post a Comment