¿Es posible hacer clic en un glyphicon y alternar entre dos funciones? Declaré un lápiz de glyphicon aquí.
var tgtEditLink = document.createElement("a"); tgtEditLink.href = "#"; tgtEditLink.setAttribute('aria-label', 'Edit'); var tgtEdit = document.createElement("i"); tgtEdit.classList.add("glyphicon", "glyphicon-pencil", "white", "tgt-edit"); tgtEdit.title = "Edit"; tgtEditLink.appendChild(tgtEdit); tgtDragbar.appendChild(tgtEditLink);los usuarios pueden hacer clic en esta clase para habilitar la función "editar" en mi aplicación. Luego quiero poder hacer clic en el mismo glyphicon y deshabilitar dicha función para otra.
$(document).on('click', '.tgt-edit', function rearrange() { $('#align-src-col').sortable(sortableOptionsSrc); return false; });El código anterior permitirá a los usuarios editar su texto.
Quiero poder hacer clic en el lápiz nuevamente, '.tgt-edit', para deshabilitar la edición y habilitar otra función. ¿Es esto posible en javascript?
¡Gracias!
Puede alternar la clase del elemento para que ya no tenga tgt-edit y tenga la clase a la que se delega la otra operación.
$(document).on('click', '.tgt-edit', function rearrange() { $('#align-src-col').sortable(sortableOptionsSrc); $(this).toggleClass(["tgt-edit", "tgt-other"]); return false; });