- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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:
<html> <head> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $.fn.person = function(prop) { var defaults = $.extend({ name: 'Amit' }, prop); // methods to be used outside of the plugin var person = { changeName: function(name) { defaults.name = name; }, getName: function() { return defaults.name; } }; return person; }; // set initial properties var person = $('#person').person({ name: 'Sachin' }); document.write('Initial name of person: ', person.getName()); person.changeName('Amit'); // printing new name document.write('<br>Changed name of person: ', person.getName()); </script> </head> <body> <div id = "person">Changes done above!</div> </body> </html>
Output
Initial name of person: Sachin Changed name of person: Amit Changes done above!
- Related Articles
- How to call a jQuery plugin function outside the plugin?
- How to call a jQuery plugin without specifying any elements?
- How to call a Java function inside JavaScript Function?
- How to call a jQuery library function?
- How to create a custom jQuery Plugin?
- How to write a custom jQuery plugin?
- How to call a jQuery function after a certain delay?
- How to call a virtual function inside constructors in C++?
- How to call jQuery function with JavaScript function?
- How to make a jQuery function call after “X” seconds?
- How to call a controller function inside a view in Laravel 5?
- How to call a JavaScript function from C++?
- How to Call a Lua function from C?
- How to call a JavaScript Function from Chrome Console?
- How to call a JavaScript function from an onClick event?

Advertisements