0

I find $("#something") and $('#something') in my project script. I am really confused trying to know the difference, if any.

Please help me clarify this.

And, also what is the use of # here? Is it must to specify that it is the id of an element?

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Manikandan
  • 589
  • 1
  • 9
  • 18

2 Answers2

2

Assuming that $ is jQuery, then # is needed to specify the ID(jQuery uses Sizzle which parses string selectors as CSS selectors), and there is no true difference between using ' or " to define a string, in Javascript.

In a language like C# ' defines a char while " defines a string.

Niccolò Campolungo
  • 11,824
  • 4
  • 32
  • 39
1

Difference between $(“something”) and $('something')

There is no difference between these two things at all in Javascript. They are identical; the choice of which type of quote to use is entirely at the discretion of the programmer. (sometimes if makes a difference if the string contains a quote mark, but that doesn't apply here).

And, also what is the use of # here? Is it must to specify that it is the id of an element?

Yes, that's exactly what it is. It selects an element with the specified ID. It's the same syntax used in CSS.

Spudley
  • 166,037
  • 39
  • 233
  • 307