The difference between the "and" characters in jQuery

Possible duplicate:
When to use JavaScript or JavaScript in two ways:

I think that $('#id')and $("#id")are both valid, so the symbol "and 'is cheething, and simply prefer to use 'instead "?

+3
source share
3 answers

Single and double quotes do the same thing in JavaScript: they limit string constants. It’s convenient (albeit a little strange) to have both types of quotes available for the same purpose, because sometimes it quotes strings with embedded quotes. One example: jQuery selector:

$('input[name="my input"]').val('');
+6
source

jQuery - JavaScript.

, ', " - - .

+1

'and "can be used interchangeably in JavaScript / jQuery.

It is a little more reliable to use '.

Why? Because it is easier to move JavaScript code between tags scriptand embedded HTML elements, the general syntax of XHTML is to wrap the event code in ""(for example, onclick="alert('foo')"). Using single quotes prevents the need to exit (for example "alert(\"foo\")") and makes it easy to move code from a string to an external script page.

0
source

Source: https://habr.com/ru/post/1782205/


All Articles