X

LATEST #JQUERY NEWS

jQuery 3.0: Fix url.indexOf is Not a Function Error


jQuery 3.0 is out, and if you started working with it and plan to work with this, then you may encounter the error “Uncaught TypeError: url.indexOf is not a function”. This error is related to jQuery 3.0 and it is occurring due to one of the change made to jQuery 3.0.

First, let’s see how this error occurs.Following is the syntax that we all use for attaching loadevent with window’s object.

$(window).load(function() { ... });

Quite familiar. Isn’t it? But if you use the same code with jQuery 3.0, then you will get the error “Uncaught TypeError: url.indexOf is not a function”. This is because .load, .unload, and .error, deprecated since jQuery 1.8, and are no more. These events were deprecated since jQuery 1.8 but were still available to use for a while, but with jQuery 3.0, they have been removed, and when you try to use them you’ll get an error. Remember, load event is removed, load method is not. “Load” method is still available, and it loads data from the server and places the returned HTML into the matched element. So how do we fix it?

jQuery team mentioned in their 3.0 release that .load.unload, and .error, deprecated since jQuery 1.8, are no more. Use .on() to register listeners. Therefore, use the following syntax to attach load event with windows object in jQuery 3.0

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

This should attach load event to windows object and it should work in all situations. But if the above code is not making a call to load event, then you can call the load event manually.

$(window).on('load', function() { ... }); //Attaches load event 
$(window).trigger('load'); //Triggers load event manually.

jQuery provides trigger event which execute all handlers and behaviors attached to the matched elements for the given event type.

Recently Published

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...

article image
»

Check all checkboxes in HTML table using jQuery

HTML tables are a very handy and useful element. They can adapt to ...

article image
»

Changing images in a loop on hover using jQuery

Why use this Function? Changing images in a loop on mouse over is a ...