I want to be able to determine wheter a jQuery object was created from an existing DOM element, or if it is new/created "on-the-fly".
Given the following examples: Example 1: HTML: <html> <body> <div id='title'><h1>Title</h1></div> </body> </html> JavaScript: var elem = $('#title'); Example 2: var elem = $('<div id='title'><h1>Title</h1></div>'); How can I tell if elem came from an existing DOM? I was assuming that I could just check the parent() - expecting the result to be null for Example 2. However, this is what I get: $('#title')parent()[0].nodeName; // returns BODY $('<div id='title'><h1>Title</h1></div>').parent()[0].nodeName; // returns DIV Any ideas?