How to call a function inside a jQuery plugin from outside?

To call a function inside a jQuery plugin from outside, try to run the following code. The code updates the name with jQuery as an example using properties:

Live Demo

      <script src = ""></script>
         $.fn.person = function(prop) {
            var defaults = $.extend({
               name: 'Amit'
            }, prop);
            // methods to be used outside of the plugin
            var person = {
               changeName: function(name) {
         = name;
               getName: function() {
            return person;
         // set initial properties
         var person = $('#person').person({
            name: 'Sachin'
         document.write('Initial name of person: ', person.getName());
         // printing new name
         document.write('<br>Changed name of person: ', person.getName());
      <div id = "person">Changes done above!</div>


Initial name of person: Sachin
Changed name of person: Amit
Changes done above!

Updated on: 12-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started