I'm trying to add a word from a word bank to a div on click. That is working correctly. Then when the user clicks on the word that has been added to the div, it will remove the word, and add it back to the word bank. right now, the on
function isn't even firing, as log("changed");
isn't showing in console.
HTML:
<div id="Response"></div>
jQuery:
/*Append clicked word bank word to TextBox */
$(document).on('click', '.bank-word', function(event) {
var myword = $(this).attr('word') + " ";
$("#Response").append("<span class='myword' word='" + myword + "' ><b>" + myword + "</span>");
$(this).hide();
});
$(document).on('click', '.myword', function(event) {
$(this).hide();
});
/*If User removes word from TextBox, add it back to word bank*/
$(document).on('change', '#Response', function(){
log("changed");
var words = $(this).val().split(' ');
$('.bank-word').each(function(){
if( words.indexOf( $(this).attr('word') ) !== -1 ){
$(this).hide();
}
else {
$(this).show();
}
});
});
log("changed");
isn't even firing.
EDIT:
How can I tell if a portion, let's say an appended span
, has been added/removed to a div
?