Is there any difference between defining variables:
var p_tr1 = $('<tr> </tr>')
$p_tr = $('<tr></tr>')
i'm using netbeans, and variables have different highlighting. I looked through FF debugger and found that variables are equals
Is there any difference between defining variables:
var p_tr1 = $('<tr> </tr>')
$p_tr = $('<tr></tr>')
i'm using netbeans, and variables have different highlighting. I looked through FF debugger and found that variables are equals
There's no difference whatsoever, historically it has been used to denote jQuery objects.
var $td = $('td') // common use case
If you use jQuery, it might be useful to know at any point if the variable you're working with is already wrapped or not.
The $
sign is just a symbol that can be used in variable names. Creating a variable a = 1
is the exact same thing as creating a variable $a = 1
, or another variable a$ap = 1
. The only thing that changes is the name of the variable. You can type a == a$ap
and it will output true
.
There is no difference, it's for code readability and easier understanding, because usually $prefix is used for a variable when you have a jQuery wrapped result.
So in case you select an element with id mydiv
:
var $mydiv = $('#mydiv');
But if you would have it's non jQuery wrapped counterpart, you would do:
var mydiv = $('#mydiv')[0];
This way you know that with the 1st one you can use jQuery functions and with second one you can't.