JQuery Object Prototype

From CoderLearner
Jump to: navigation, search

Description

All objects have a prototype property. It is simply an object from which other objects can inherit properties. Object prototype in jQuery is getting its from javaScript.


Syntax

  • There are two ways you can create the object prototype.
jQuery.prototype.NAME = function() {} 

jQuery.fn.NAME = function() {}

Example

<html>
    <head>
        <title>Object</title>
        <script type="text/javascript" src="/js/jquery-1.8.3.js"></script>
        <script type="text/javascript">
            jQuery.fn.showText=function(){
                return this.html("This is coderlearner.com");
            };
            
            
            $().ready(function() {
               $('#showtext').showText();
            });
        </script>
    </head>
    <body> 
        <div id="showtext"></div>
    </body>
</html>

Result

This is coderlearner.com