Uncaught TypeError: e.indexOf is not a function in JQuery

Last updated 4 years, 6 months ago | 11955 views 75     5

Tags:- JQuery

JQuery | Uncaught TypeError: e.indexOf is not a function

This error occurs because you may try to load an event handler which is removed from the latest version of jQuery. Event handler like .load(), .error(), .toggle() etc. that all are deprecated since jQuery 1.8

To fix such errors you will have to use .on( "load", handler ) to attach events with objects in jQuery 3.0.

Let's see an example of the load(handler).

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

		alert("window load");

In the above code .load(hendler) is used. As .load(hendler) has been removed in jQuery 3.0, the code throw an error "Uncaught TypeError: e.indexOf is not a function" in the browser console.

jquery.min.js:2 Uncaught TypeError: e.indexOf is not a function
    at k.fn.init.k.fn.load (jquery.min.js:2)
    at document_ready_function.html:9

This error can be fix by using .on( "load", handler ) instead of .load( handler )

<!DOCTYPE html>
<html lang="en">
        <title>JQuery window load</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        $(window).on('load', function(){
            alert("window load");