This is how you can check whether the div exists: if ( $("#message").length ) { $('#message').text("Hello!"); }
if ( $("#message").length ) { $('#message').text("Hello!"); }