jQuery not firing after ajax
Posted: Sun Jan 25, 2009 8:14 am
My jQuery does not work on content that I have injected into the Dom with ajax.
Here is my injection...
Here is the function chatroom...(chatData works, but my click code below does not)
Any ideas? Thanks
Here is my injection...
Code: Select all
$('div#chatroom').load('php/chatroom.php', '', $.chatroom());Code: Select all
jQuery.chatroom = function () {
// load messages on page entry
$.chatData(); // THIS WORKS
// save & load on submit
$('input#submit').click( function(event) { // THIS DOES NOT WORK
event.preventDefault();
var name = $('input#name').val(); // get name
var message = $('textarea#message').val(); // get message
if (name != '' && message != '') {
$.post("php/save.php", { name: name, message: message } ); // save message
$.chatData();
$('textarea#message').val(''); // reset type area
}
else {
$('div#response').empty();
$('div#response').append('<img src=\'images/close.png\' alt=\'Close\'><p class=\'whiteText\'>You must fill your name and message</p>');
$('div#response').fadeTo('fast', 0.7).slideDown(500);
// close response/feedback box
$('div#response img').click( function(event) {
$('div#response').slideUp(400);
});
}
});
}