5

In the jQuery accordion API, it says "If the accordion is collapsing, ui.newHeader and ui.newPanel will be empty jQuery objects."

How can I check if ui.newheader is an empty jQuery object? I've tried it like this:

if ($(ui.newHeader) == null)
{
    ...
}

,like this:

if (ui.newHeader == null)
{
    ...
}

and this:

if ($(ui.newHeader) == "")
{
    ...
}

So basically, this is a question about jquery/javascript syntax :) Thanks

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
taevanbat
  • 425
  • 1
  • 8
  • 17
  • 3
    It's not really a syntax question - all three of the things you tried are valid JavaScript syntax, they just don't do what you want to do. – nnnnnn Jun 29 '13 at 12:38

3 Answers3

5

What you want is to know if there is 0 element in the set. Do it like this :

if ($(ui.newHeader).length==0) {
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
1
if (!$(ui.newHeader).length)

or

if (!$(ui.newHeader)[0])
A. Wolff
  • 74,033
  • 9
  • 94
  • 155
1

jQuery object is array like collection. So, it is empty means, it's length property is 0.

if(!$(ui.newHeader).length) {...}