if ($('#mything').length == 0) { // Does not exist } else { // Is there }In fact you don't even need the compare, this is valid:
if ($('#mything').length) { // Is there }Do NOT write length() We were just checking for one id but it works for any selector. For example to see if the document has any images:
if ($('img').length == 0) { alert('No images'); }