Check whether the div exists [Jquery]

This is how you can check whether the div exists:

if ( $("#message").length ) {
$('#message').text("Hello!");
}