3

Is it legal in jQuery to place a comment in the middle of a chained query?

$('#deForm :input')
    .not('.notHide')  //Commment
    .not('.alsoNotHide');

I am testing a code like this but it has a strange behavior, and I would like to be sure, its not a refresh issue because for me theres no change in behavior.

Also is it preferable to use single quotes or double quotes for selectors?

Whimusical
  • 6,401
  • 11
  • 62
  • 105

5 Answers5

4

There is not problem with this whatsoever, as long as the comment is the only thing on the line (rest of the line will be literally ignored by the interpreter).

If in doubt you can always try to change it to:

/* Comment */

But using // is not a problem.

Bart Platak
  • 4,387
  • 5
  • 27
  • 47
3
  1. yes its legal to have comments like that.
  2. usually, it doesnt matter which quotes you use. See accepted answer here
Community
  • 1
  • 1
robasta
  • 4,621
  • 5
  • 35
  • 53
3

Your question has nothing to do with jquery, the double quotes serve the identical purpose like single quotes, its just a matter of preference.

And the comment style is perfectly valid.

Bojan Jovanovic
  • 1,439
  • 2
  • 19
  • 26
1

Yes, that is perfectly legal. Its just javascript functions being called and the jQuery library shouldn't even realise that the comments are there.

And I tend to use single quotes for all javascript strings and that is generally what I see so I assume that is "standard".

Chris
  • 27,210
  • 6
  • 71
  • 92
1

If you have newline for the code, then it's ok. If that's in one line, then it will be a problem.

xdazz
  • 158,678
  • 38
  • 247
  • 274