I am trying to append a div with a button so that when when it is clicked I can execute a function.
I am currently appending a div like this.
$('.window').append('<div class="message messageUser2"><div class="bubble bubbleUser"><p class="chatText"><div class="chat-input"><textarea type="text" class="inputChatText" id="message" name="message" placeholder="enter your message" data-required/></div></p><img type="button" class="test" src="img/up.png"></img></div></div>');
It appends and everything looks right on the page but when I click the button/img nothing happens. For starters i'm just trying to console log the click but eventually want a function to run but cant do this until its clickable.
$('.test').on('click', function() {
console.log("The test button was clicked");
});
As you can see here its appending even according to the console
Anyone have any ideas of what I need to do to actually get this to be a clickable event after I append it? Thanks