Q:

Check if existing jQuery object (not a selector) exists in the DOM

Example:
var $doesNotYetExistInTheDOM = $('<span/>'); // create new jQuery element
                                             // outside of the DOM
var $doesExistInTheDOM = $('span');  // selected element from the DOM

Is there a way to check if a jQuery selected object exists in the DOM?

A:

You can check by trying to find it in the document:
!!$(document).find($doesNotYetExistInTheDOM).length // false
!!$(document).find($doesExistInTheDOM).length // true

