Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active April 25, 2019 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c05701f92ab0e8f7467420c329385be8 to your computer and use it in GitHub Desktop.
Save parzibyte/c05701f92ab0e8f7467420c329385be8 to your computer and use it in GitHub Desktop.
$(document).ready(function () {
const $select = $("#miSelect");
const opcionCambiada = () => {
console.log("Cambio");
};
$select.change(opcionCambiada);
const agregar = () => {
const valor = new Date().getTime();
$select.append($("<option>", {
value: valor,
text: valor
}));
};
const limpiar = () => {
$select.empty();
};
const mostrar = () => {
const valor = $("#miSelect :selected").val(),
texto = $("#miSelect :selected").text();
alert(`Texto: ${texto}. Valor: ${valor}`);
};
$("#btnAgregar").click(agregar);
$("#btnLimpiar").click(limpiar);
$("#btnMostrar").click(mostrar);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment