Is the with statement correct $
to assign DOM items to work with later?
If not, should I assign them to normal variables with let
?
$table = $('#tblActividades');
$nuevo = $("#btnNuevo");
$buscar = $("#txtBuscar");
$ok = $("#ok");
$araba = $("#cmbAraba");
$bizkaia = $("#cmbBizkaia");
$gipuzkoa = $("#cmbGipuzkoa");
$nuevo.click(function () {
AbrirModal(this);
});
$ok.click(function () {
RefrescarTabla();
});
It is by convention to use
$
to refer to DOM objects accessed via jQuery , for aesthetics (to differentiate which variables will be used from the DOM in jQuery), but 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 usevar
, but in some cases you may want to usevar
local scope as well.O well
But you should always define the variables, you can get a lot of errors if you don't.