jQuery Topics

Solutions to Common jQuery Errors

jquery-errors-post

Let’s face it, nobody is perfect! Everyone makes mistakes now and then and jQuery is the same – although they have an excellent bug fixing team who are fixing up errors and enhancing jQuery around the clock errors may appear from time to time.

In light of this and the fact that I’ve been developing with jQuery for quite a while now and every now and then an error will show in the Firebug Console and “I have to Google it”. I thought I would share some of the most common errors so that when you encounter them you might have some idea of how to solve the puzzle.


Error: “jquery.1.4.2.js error “a is null””

jquery.1.4.2-error

Possible Causes

a is null
[Break On This Error] a))();else c.error("Invalid JSON: "+a)...(d)if(i)for(f in a){if(b.apply(a[f],
jquery....min.js (line 29)

I was thinking it might have something to do with this line failing because there was no matches.

$.each(rawData.match(secureQueryRegex), function(index, currentQuery)

Then, I was thinking it may have been the size of data as it was 69,443 characters long…

Possible Solutions

But I eventually found out it was bad characters inside the data string (which was grabbed directly from HTML). See cleanHTML() function to remove bad characters form HTML.

rawData =  rawData.replace(/[^<>a-zA-Z 0-9]+/g,'');  /* clean up for match() statement */

Specific Versions

Seen in 1.4.2


Error: “SyntaxError: invalid object initializer”

invalid-object-init

Possible Causes

Object declaration syntax error.

$.getScript(
{
	'http://www.domain.com/js/preview.js'
});

OR

$("div").css(
{
    padding:'0',
    margin,'4px'
});

Possible Solutions

Remove the brackets the getScript() function can be called with just the url. The same applies to any other object declaration or function call with an object that doesn’t accept one.

$.getScript('http://www.domain.com/js/preview.js');

Change the comma to a semi colon.

$("div").css(
$("div").css(
{
    padding: '0',
    margin: '4px'
});

Specific Versions

Seen in 1.4.2


Error: “uncaught exception: Syntax error, unrecognized expression: [object HTMLLIElement]“

syntax-error

Possible Causes

This seems like a jQuery selector error. It seems to appear more frequently in v1.4.2 or earlier so try updating to the latest version of jQuery.

$(this+' a').css(
var req = $("input[@name=required]").val();

Possible Solutions

Not sure but take a look at your selectors and make sure they work properly. Try including the full jQuery versions first to get better error info on what might be causing the problem.

@ is old selector syntax.

var req = $("input[name=required]").val();

Specific Versions

Seen in 1.4.2


Error: “SyntaxError: missing ) after argument list”

no-idea

Possible Causes

Missing off closing brackets or curly braces.

})(jQuery

Possible Solutions

})(jQuery);

Specific Versions

Seen in 1.4.2


Error: “SyntaxError: missing : after property id”

mssing-property-id

Possible Causes

This is a repeat of the object initialize error but it’s caused by Using curly brackets when they are not needed.

$.getScript(
{
	'http://www.domain.com/js/preview.js', function(data, textStatus){
   console.log(data); //data returned
   console.log(textStatus); //success
   console.log('Load was performed.');
});

Possible Solutions

$.getScript('http://www.domain.com/js/preview.js', function(data, textStatus)
	{
	   console.log(data); //data returned
	   console.log(textStatus); //success
	   console.log('Load was performed.');
	}
);

Specific Versions

Seen in 1.4.2


Error: “TypeError: jsSrcRegex.exec(v) is null”

Possible Causes

Caused by double exec on same regex OR caused by invalid html “jsSrcRegex.exec(v) is null”.

console.log(jsSrcRegex.exec(v));
console.log(jsSrcRegex.exec(v)[1]);

Possible Solutions

Check the html first:

if(jsSrcRegex.exec(html)){
	console.dir(jsSrcRegex.exec(html)[1]);
}

OR

Use recompile the regex:

console.log(jsSrcRegex.exec(v));
jsSrcRegex.compile();
console.log(jsSrcRegex.exec(v)[1]);

Specific Versions

n/a


Error: “XML descendants internal method called on incompatiable object”

xml-error

Possible Causes

Double full stop in jQuery chain commands.

$('.'+inElem)..removeClass('mouseover').addClass('selected');

Possible Solutions

To fix simply remove the double full stop.

Specific Versions

n/a


Error: “undetermined string literal”

You may have seen this one before! :)
string-error

Possible Causes

Many possible causes: could be that you put code where a selector should be or multiple line strings or wrong string format (bad characters) or angle brackets etc.

Possible Solutions

See jQuery Undetermined String Literal Error for a very detailed explanation on this error!

Specific Versions

n/a


Error: “Syntax Error: Unrecognized Expression”

jquery-error-unrecognised-expression

Possible Causes

Missing attribute name in selector.

$('input["depDate"]').val(departureDate);

Possible Solutions

Add in the name attribute (or id, class etc) into the selector.

$('input[name="depDate"]').val(departureDate);

Specific Versions

n/a


Error: “SyntaxError: syntax error”

string-error
(click image to enlarge)

Possible Causes

Well, this error is very generic and there might be a number of reasons why is happens but in this example you can clearly see it was caused by an extra “+” in the jQuery selector.

$('.itemColumn'+currentColNum+).append(v);

Possible Solutions

Unfortunately, on this one you’ve just got to carefully check through your syntax and make sure you don’t have any mistakes. Try using something like jshint or another js checker to assist.

$('.itemColumn'+currentColNum).append(v);

Specific Versions

n/a


Error: “(d || “”).split is not a function”

live-hover-error

Possible Causes

Sorry, I found this error and took a screenshot but can’t remember how i got it! I think it might be a live image hover bug in jQuery 1.4.2 but not sure.

Here is something bug 862 similar which i found (it was logged 5 years ago aha).

Sometimes you see a similar error which reads “jquery error d is undefined” or such which I saw a few times in jQuery 1.5.

Possible Solutions

Update to latest version of jQuery.

Specific Versions

Seen in 1.4.2


After seeing all those errors, here’s something to cheer you up!

smiley-face

Or you can see more errors and bugs on the Official jQuery Bug Tracker.

If you find any errors please leave a comment with the error and solution and i will add it to the list!

Cheers!


Read the full/original article at jQuery4u

    Related Posts

    Comments are closed.

    jQuery Resources

    Learn more about jQuery

    jQuery News & Links

    I only just found out that the jQuery validation plugins has a validation rule called “remote” which can be used ...

    jQuery function to check if horizontal scroll is present – hasHScrollBar() – (or vertical check below also, util function to ...

    jQuery function to Set any DOM Element to Top View (bring to front) using CSS Z-Index property.

    Is it possible to declare arrays in JavaScript object literal notation? Example 1 – this works with arrays Declaration: Storage ...

    To get the a variables type using jQuery there is a jQuery function called .type() which returns “array”, “string”, “number”, ...

    In this post you can find tutorials which explain step by step different API use cases with jQuery like Google ...

    For valuable work on creation of sites you need a good comfortable editor necessarily. There are many requiring paid products ...

    Today we are sharing with you a collection of awesome jQuery Camera Photo plugins. They offer a range of image ...

    Back in the day, if you saw something that was animated on a website it was automatically assumed to be ...

    In this post, we have compiled a list of 10 jQuery HTML5 Audio players available today, most allow native audio ...

    jQuery Mobile is a powerful framework for making mobile web applications. But can we use it to convert existing desktop ...

    I have jotted a quick post on a Basic JavaScript Regular Expression Example to give beginners out there a taste ...

    In April 2012′s edition of Interestingly Random JavaScript, jQuery and Web Development we bring you some very cool stuff such ...

    In this post we are sharing you a roundup of 10 really jQuery plugins as of today. Pretty cool plugins ...

    As always expected from the jQuery community, the compilation we have for you today are some good and impressive recently ...

    A collection of jQuery PNG/JPEG/GIF plugins that enables image animation, cartoon-like background, etc… let them help you design displays for ...

    A collection of JavaScript/jQuery Zip/File/Compressor plugins that allows you to minify your JS code and compress your JS files ready ...

    Quick jQuery code snippet on how to keep an element in view. For demo scroll down on any page on ...

    Here is what I think is the best and most reliable way to load jQuery library and jQuery UI Libraries. ...

    jQuery code snippet which outputs all attributes of element using the default .attr() function on any dom element(s). usage: output:

    More Links & News

    Community Resources

    Use jQuery and the Google Maps API to create your own map application.

    Super cool and easy way to get stylish tooltips with jQuery.

    The right way to include the jQuery library in WordPress.

    Share a resource