0

What is difference between following two syntax's in JQuery. Some people follow syntax 1 and some syntax 2

Syntax 1
$('#element_id') 

OR

Syntax 2
$("#element_id")
Ali
  • 3,545
  • 11
  • 44
  • 63

2 Answers2

1

This has nothing to do with jQuery. In JavaScript, you can use either single or double quotes around string literals. All it affects is whether you have to escape that kind of quote within the string.

E.g.:

var s1 = "I'm a double-quoted string, so double quotes " +
         "like this: \" have to be escaped, but single quotes " +
         "like the one in don't, don't.";

var s2 = 'I\'m a single-quoted string, so single quotes like that ' +
         'one just now in I\'m have to be escaped, but double quotes ' +
         'like this: " don\'t.";

Whether you use single or double quotes makes no difference to the resulting string, just what you have to escape when writing it.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

Its common to use " in HTML. So if you want a selector like:

$('.foo[name="bar"]');

or something like:

$('<div name="bhlkh" .../'>...

the single quote could make things easier.

I prefer to always use the '.

Ferret
  • 1,440
  • 2
  • 12
  • 17