Jquery giving error a.indexOf is not a function

enter image description here

I’m using WordPress in which I’m using custom script and its giving error a.indexOf is not a function.

My custom javascript file is cus.js
and below is its code

$(window).on('load', function(){

    alert('hsdsdsi');
        $( ".disabled" ).each(function(index, element){
            alert('hsdsdsiasdasdfasfaf');


        alert(element.closest("li").attr('class'));
        });
    });

In functions.php

I’m using following code because I want script to function only when pages with particular template are loaded.

add_filter( 'template_include', 'my_load_script_for_template', 1000 );
function my_load_script_for_template( $template ){
     if(is_page_template('template-topcharts.php'))
        wp_enqueue_script(get_template_directory_uri() . '/js/cus.js');

return $template;
}

And in another function rehub_framework_register_scripts() where all scripts are getting registered i have added following code

function rehub_framework_register_scripts() {

    wp_register_script( 'cus', get_template_directory_uri() . '/js/cus.js', array('jquery', 'rehub'), '1.0.0', true );
}

But error is coming in other files custom.js

Read more here: Jquery giving error a.indexOf is not a function

Leave a Reply

Your email address will not be published. Required fields are marked *