• Now Online : 42
  • admin@codemyne.net

Using Multiple Libraries:
You can use multiple libraries all together without conflicting each other. For example you can use jquery and Moo Tool javascript libraries together.
jquery-noConflict() Method:
Many javascript libraries use $ as a function or variable name, just as jquery does. In jquery’s case, $ is just an alias for jquery, so all functionality is available without using $.
Run $.noConflict() method to give control of the $ variable back to whichever library first implemented it. This helps to make sure that jquery doesn’t conflict with the $ object of other libraries.
Definition and Usage:

The noConflict() method releases jquery’s control of the $ variable. This method can also be used to specify a new custom name for the jquery variable. This method is useful when other javascript libraries use the $ for their functions.

Syntax:
$.noConflict(removeAll)

Parameter Description
removeAll Optional, A Boolean value that specifies whether or not to release jquery’s control of All jquery variables(including “jquery”)

    <html>
    <head>
    <script type=”text/javascript” src=”jquery.js”></script>
    <script type=”text/javascript”>
        Var jq=$.noConflict();
        Jq(document).ready(function(){
        Jq(“button”).click(function(){
        });
        });
    </script>
    </head>
    <body>
        <h2>This is heading</h2>
        <p>This is paragraph.</p>
        <p>This is another paragraph.</p>
        <button>Click me</button>
    </body>
    </html>
    

Here is simple way of avoiding any conflict:

        //Import other library
        //Import jquery
        $.noConflict();
        //code that uses other library’s $ can follow here.
        

This technique is especially effective in conjunction with the ready() method’s ability to alias the jquery object as within the ready() we can use $ if we wish without fear of conflicts later:

                                                    //Import other library
                                                    //Import jquery
        $.noConflict();
        jquery(document).ready(function($){
            //code that uses other library’s $ can follow here.
        });
        //code that uses other library’s $ can follow here.
        DOM element
        

Comments/Suggestions are invited. Happy coding......!

Comments Post a Comment