1

I had a subtle typo in a javascript I was testing - a double-apostrophe instead of a single. Can you spot it?

$('#visa, #mastercard').click(function() {
    $('#creditCard input').attr('disabled', false).css('backgroundColor",''); 
    $('#creditCard label').css('color','');
}); 

My question is - is there a way to have this error flagged in the browser? When I look at the console in both Chrome and Firefox (firebug), nothing shows up.

3
  • 2
    The syntax highlighting really helps in spotting it :)
    – Ry-
    Feb 25, 2012 at 18:27
  • Are you writing that code in Notepad? :P Feb 25, 2012 at 18:33
  • The problem, of course, is 'backgroundColor" with the unmatched single-double quote. I've done this kind of things many times. I second the idea of using syntax highlighting in your editor (I use UltraEdit from IDM), but the thing that has helped me has been to have a strict set of rules for using quotes. For me it always works best to use ' to start with and then " for quoted items internal to the '. I don't know of any way to have the browser flag it for you.
    – Terry
    Feb 25, 2012 at 18:50

4 Answers 4

2

You should be getting this error (with information about the file and line number):

SyntaxError: unterminated string literal

Use the syntax highlighting feature of your IDE to detect such errors.

4
  • A good IDE for Windows is Notepad++. I myself use Kate (Linux).
    – Rob W
    Feb 25, 2012 at 18:50
  • How do I see this error? I look at Console in firebug, but nothing. Same with tools, javascript console, console on Chrome. Feb 25, 2012 at 19:06
  • any idea how I can see this in the browser? It's escaping me - haven't been able to find it. Feb 25, 2012 at 19:28
  • @JackBeNimble Firefox/Chrome: Ctrl+Shift+J, clear the console and Reload page. The error should show up.
    – Rob W
    Feb 25, 2012 at 22:21
1

The line

$('#creditCard input').attr('disabled', false).css('background-color',''); 
$('#anAirlineName').css('background-color",'');

Should be

$('#creditCard input').attr('disabled', false).css('background-color',''); 
$('#anAirlineName').css('background-color','');

after background-color it should be single apostrophe not the double one.

1

If you have an editor with highlighting, it'll show up immediately since the colors will be reversed every line after that. It even shows up on Stack Overflow.

0

For what it may be worth, I stuck the following in my code:

$('#anAirlineName).css('backgroundColor",'');

and I did get in the Firebug error console 'unterminated string literal' and it gave the filename name and line number.

The way I'm set up, I don't see the Firebug error console, unless I click the rightmost red x on the Firebug menu line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.