Looks like the message is loaded dynamically and the m_close
might be added to the message
element using showMessage()
method.
so try
$( document ).ready(function() {
showMessage();
$( '#message' ).slideDown( 'fast' );
//Hide Message//
$( '#message' ).on('click', '#m_close', function( event ) {
$( '#message' ).slideUp( 'fast' );
});
//---//
$( '#m_button' ).click(function( event ) {
showMessage();
$( '#message' ).slideDown( 'fast' );
});
});
when you use click
to register a click event handler, it register the handler to only those elements that exists in the dom at that moment. when you call showMessage
again teh existing m_close
is removed and a new one is created so the click
handler is no more attached to the new element. The solution here is to use event delegation as shown above