I am trying to submit a form that I dynamically created. I am using the .submit, but it is not working. Here is my code
var $message = $('.message');
$message.submit(function(e){
console.log("Test");
});
$(document.body).on('click','.button', function(e) {
console.log($(this).val());
var $input = '';
$input = $('<p>Chat with '+$(this).val()+'</p>');
$input.append('<div class = "chat" style="height:200px"></div>');
$input.append('<form class="message">');
$input.append('<input size = "35" class="messages">');
$input.append("<br><input type='submit' class='send_message' value = 'Send' />");
$input.append('</form>');
$input.appendTo($("#contentWrap"));
});
The code for document.body created the form. However, when I click the submit button nothing happens.
I also tried
$('#contentWrap').on("submit", ".message", function(e){
console.log("Test")
});
$(parent).on(event, child, function) is what most of the posts I read say to do. However, I must be doing something else wrong.
Here is the fill front end code in js fiddle https://jsfiddle.net/55Ln0wgu/