Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which quotation marks to use and when?

for example here in documentation http://api.jquery.com/attribute-contains-selector/ it says

$('input[name*="man"]')

I would write instead

$("input[name*='man']")

is there any reason to use single or double quotation marks on inside or outside ?? is it just a matter of taste?

like image 864
IAdapter Avatar asked Jan 15 '12 09:01

IAdapter


People also ask

How do you know which quotation marks to use?

If you use single quote marks, you should use double speech marks for a quote within a quote. If you use double quote signs, you should use single quotation signs for a quote within a quote. Examples: "When I say 'immediately,' I mean sometime before August," said the manager.

What is the difference between single and double quotation marks?

General Usage Rules In America, Canada, Australia and New Zealand, the general rule is that double quotes are used to denote direct speech. Single quotes are used to enclose a quote within a quote, a quote within a headline, or a title within a quote.

What are single quotation marks used for?

Single quotation marks are also known as 'quote marks', 'quotes', 'speech marks' or 'inverted commas'. Use them to: show direct speech and the quoted work of other writers. enclose the title of certain works.

What are double quotation marks used for?

Use double quotation marks (“”) around a direct quote. A direct quote is a word- for-word report of what someone else said or wrote. You use the exact words and punctuation of the original.


1 Answers

It's just a matter of taste, and sometimes convenience.

You are using quotation marks both in Javascript and in a jQuery selector, and in both cases you can use either apostrophes (') or quotation marks (") to delimit strings.

In some cases it's more convenient to use one type over the other, for exampe when you have Javascript code in an HTML attribute, as apostropes doesn't need to be escaped:

<div onclick="alert('Hello world!');">

compared to:

<div onclick='alert(&quot;Hello world!&quot;)'>
like image 76
Guffa Avatar answered Oct 22 '22 17:10

Guffa