0

What is the difference between using this

$('.container').text();

and this:

$(".container").text();

both (") and (') work but what's the difference?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143

5 Answers5

5

The long and short of it is that there is no difference whatsoever.

Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
1

There is no difference in this case, you can use either apostrophes (') or quotation marks (") to delimit strings in Javascript.

Where you can see a difference, is when you need to use apostrophes or quotation marks inside a string. If you delimit a string using apostrophes, you have to escape apostrophes inside the string, but not quotation marks, and vice versa.

Example:

var html = '<div class="info"></div>';

vs.

var html = "<div class=\"info\"></div>";
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

from my experience, generally no differences.

James Lin
  • 25,028
  • 36
  • 133
  • 233
0

They are the same, there is no difference, just a coding convenience.

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
0

There is no difference, except for when you want either double or single quotes to appear inside your string:

$(".continer[rel='hello']");
osahyoun
  • 5,173
  • 2
  • 17
  • 15