Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create a basic plugin using jquery

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 268
    Comment on it

    If you want to make a functionality that can be used anywhere in the code. For example, you want some method that can be called on the jquery selection and it can perform number of operations on the selection. For this, you can write a plugin.

    For example if we want to create a plugin that makes color of the text red within set of elements(p, span, a). Then we have to add a function named method1 to $.fn and it will work as other jquery object methods.

    1. $.fn.method1 = function() {
    2. this.css( "color", "red" );
    3. };
    4.  
    5. $( "p" ).method1();
    6. $("span").method1();
    7. $("a").method1();

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: