1// Check if an element currently exists
2if ($('#element').length) {
3
4}
1$(document).ready(function() {
2 var $myDiv = $('#DivID');
3
4 if ( $myDiv.length){
5 //you can now reuse $myDiv here, without having to select it again.
6 }
7
8
9});
1$(function() {
2 var $button = $(".the_button");
3 alert (isStale($button));
4 $button.remove();
5 alert (isStale($button));
6});
7
8function isStale($elem)
9{
10 return $elem.closest("body").length > 0;
11};