That won't work because $() *always* returns a valid jQuery object even if there are no matching elements. This allows you to write code like $('.foo').hide() without worrying about whether there are any elements with class="foo" or not.
Instead (as pointed out elsewhere in the thread), check the .length property. > not sure, this is untested but might work(not sure what > jQuery return if nothing is found) > > if($('#id')) > { > //it exists > } > else > { > //it does not > } > > what is the best way in jquery to check wether an id exists ?