When a button is clicked a listener fires and a modal opens, and I need to get the info from the button clicked to be passed into the listeners that fire when stuff happens inside the modal.
My JavaScript:
$('li.tab').on('click', 'span.edit-tab', function() {
var elem = $(this);
var tabName = elem.parent().text();
tabName = tabName.replace(/s*$/g, '');
$('#tab-name').val(tabName);
$('#tab-name').on('keypress', function(elem) {
var appendedSpan = '';
appendedSpan += ' <span class=edit-tab glyphicon glyphicon-pencil ';
appendedSpan += 'data-toggle=modal data-target=#edit-tab-modal></span>';
var newName = $(this).val() + appendedSpan;
el.parent().html(newName);
});
});
I'm trying to pass in the element that triggered the modal to be passed into the listener of an input, but no matter what I try to pass in, the variable elem
is the jQuery object for #tab-name
, not for span.edit-tab
. Any thoughts?