hj wrote:


On Jul 9, 10:19 am, Felix Geisendörfer <[EMAIL PROTECTED]> wrote:
I've just been wondering if jQuery has some syntactic sugar for checking
if an element exists. I know the following works:
--------------------------------------------------------
if ($('#my-element').length) {
     // #my-element exists}

--------------------------------------------------------
but is there also something similar to the following?:
--------------------------------------------------------
if ($('#my-element').exists()) {
     // #my-element exists}

Don't get me wrong -- I *really* like and appreciate jQuery. But there
is value
in knowing the DOM API. For a simple test like this one: "does an
element with
this ID exist?", I'd simply say:

  if (document.getElementById('my-element')) {
    // and so on
  }


Of course you can do it like that, but the question in this thread wether jQuery should supply a convenience method for such a task...



--Klaus

Reply via email to