How jQuery Works in WordPress [duplicate]

error is coming because of jQuery.noConflict();
You do not need to add jQuery.noConflict(); in wordpress files because by default wordpress supports jQuery but if you want to use $ then you can use this way without using wp_enqueue_script(“jquery”)

If the script is being loaded in the footer (which you should be doing in the vast majority of cases) you can wrap the code in an anonymous function (technically any IIFE) where you pass in jQuery to be mapped to $.

        (function($) {

            // $ Works! You can test it with next line if you like
            // console.log($);

        })( jQuery );

If you absolutely need to load the scripts in the header, you’ll probably need to use a document ready function anyway, so you can just pass in $ there.

            jQuery(document).ready(function( $ ) {

                // $ Works! You can test it with next line if you like
                // console.log($);

            });