$('#id').length may not be a boolean value, but $('#id').length>0 is. However, in the contexts where you're likely to use this, it doesn't matter:
if( $('#id').length ) ... or: $('#id').length ? ... : ... In either of those cases, the length property works fine for the test, regardless of whether it's a boolean or a number. > Well, just to split hairs, the length property returns a number, not a > true boolean. You could also use: > > $('*').is('#myId') or you can reverse it like so: $ > ('#myId').is('*') > > The .is() method does return a boolean. An advantage is that you can > apply this to a subset of elements, for example: > > $('a').is('#myId') > > $('#id').length>0 ? > > > what is the best way in jquery to check wether an id exists ?