07 May, 2010
How to check if div exists in jQuery
This is one of the most commonly used piece of code for jQuery. Often times, we need to check if a div/element exists in the page before processing a block of script (eg: replacing the content of the div).
if ( $("#message").length ) {
$('#message').text("Hello!");
}
Love what you've just read? Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
Other similar posts that you might be interested in:
- Display thickbox on page load
- Creating a Contact Form in jQuery Mobile and PHP
- How to customise WordPress Admin Login page
- 10 Website Optimisation Tips for Web 2.0 Websites
- Check username availability using AJAX and jQuery
- How to customise your Facebook Fan Page with FBML
- Top 10 jQuery Mobile Code Snippets that you need to know
Hello! Welcome to Web development blog! My name is Ei Sabai and on this blog, I write about web development, mobile app development, latest web technologies and the likes. Read more 

