Articles in this section
Category / Section

How to render the components on using JQuery in the noConflict mode?

3 mins read

JQuery.noConflict()

JQuery by default, uses $ as an alias for JQuery. Many JavaScript libraries use $ as a function or variable name. This may cause conflicts. To avoid this, use JQuery.noConflict() immediately after JQuery is loaded onto the page and before you use JQuery. You can also refer to the following link to know more about the JQuery.noConflict method.

https://api.jquery.com/jquery.noconflict/

Ways to use Syncfusion JS components while using ‘noConflict()’

The following suggested methods or approaches are provided by JQuery. The same is applicable for using the Syncfusion EJ components.

Create an alias for ‘$’

HTML

<head>
    <!--Contains the necessary theme for our components-->
    <link href="default-theme/ej.widgets.all.min.css" rel="stylesheet" />
    <!--dependency script files-->
    <script src="scripts/jquery-1.10.2.min.js"></script>
    <script src="scripts/jquery.easing.1.3.js"></script>
    <script src="scripts/jquery.globalize.js"></script>
    <!--contains the necessary scripts to render all the web components-->
    <script src="scripts/ej.web.all.min.js"></script>
    <script>
        //release the hold on the $ shortcut identifier.
        var $jq = jQuery.noConflict();
    </script>
</head>

 

HTML

                    <div class="control">
                        Select a file to upload
                                <div class="posupload">
                                    <div id="UploadDefault"></div>
                                </div>
                    </div>
    <script type="text/javascript">
        //$jq is used instead of '$'
        $jq(function () {
            // here $jq is the alternative for '$'. So, we need to use this sign while rendering and while using EJ components
            $jq("#UploadDefault").ejUploadbox({
                saveUrl: "saveFiles.ashx",
                removeUrl: "removeFiles.ashx",
                multipleFilesSelection:true
            });
        });
    </script>

Use an Immediately Invoked Function Expression

By using this approach, you can continue to use $ sign for EJ components.

    <script type="text/javascript">
        (function ($) {
            // Here, we can render our components using '$'
            $("#UploadDefault").ejUploadbox({
                saveUrl: "saveFiles.ashx",
                removeUrl: "removeFiles.ashx",
                multipleFilesSelection: true
            });
        })(jQuery);
    </script>

Use the Argument that is Passed to the jQuery( document ).ready() Function

    <script type="text/javascript">
        jQuery(function (jq) {
            // Here, we can render the components using '$' or with parameter specified
            jq("#UploadDefault").ejUploadbox({
                saveUrl: "saveFiles.ashx",
                removeUrl: "removeFiles.ashx",
                multipleFilesSelection: true
            });
        });
    </script>

You can also refer to the following JQuery link to know more about this.

https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied