It is by convention the fact of using $
to refer to DOM objects accessed by jQuery , by aesthetics (to differentiate which variables will be used from the DOM in jQuery), but it is not necessary.
But you should always, as a good practice, define the scope of the variable ( var
= global scope | let
= local scope), you can always use var
, but in some cases you may want to use var
also in local area.
var $table = $('#tblActividades');
var $nuevo = $("#btnNuevo");
var $buscar = $("#txtBuscar");
var $ok = $("#ok");
var $araba = $("#cmbAraba");
var $bizkaia = $("#cmbBizkaia");
var $gipuzkoa = $("#cmbGipuzkoa");
$nuevo.click(function () {
AbrirModal(this);
});
$ok.click(function () {
RefrescarTabla();
});
Or
let $table = $('#tblActividades');
let $nuevo = $("#btnNuevo");
let $buscar = $("#txtBuscar");
let $ok = $("#ok");
let $araba = $("#cmbAraba");
let $bizkaia = $("#cmbBizkaia");
let $gipuzkoa = $("#cmbGipuzkoa");
$nuevo.click(function () {
AbrirModal(this);
});
$ok.click(function () {
RefrescarTabla();
});
But you must always define the variables, you can have many errors if you do not ..