Saturday, February 11, 2017

jQuery extend prototype

It is important that you can extent jQuery to improve your work environment. Below is a code snippet to do this as simple:

If you write your code in some-file.js then follow below:


(function () {
    $.prototype.hi = function () {
        this.html("Prototype invoked...")
        return this
    }
})()

Else if you write your code in <script> tag then follow below:


$.prototype.hi = function () {
    this.html("Prototype invoked...")
    return this
}

Example of usage:


$(".class").hi()

No comments:

Post a Comment