0

What is the difference between using this

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

and this:

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

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

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111

5 Answers5

5

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

Jacob Relkin
  • 156,685
  • 31
  • 339
  • 316
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
  • 666,277
  • 106
  • 705
  • 986
0

from my experience, generally no differences.

James Lin
  • 22,616
  • 32
  • 117
  • 213
0

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

Mahmoud Gamal
  • 75,299
  • 16
  • 132
  • 159
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,057
  • 2
  • 16
  • 14