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
  • 572,313
  • 128
  • 898
  • 1,281
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
  • 355,860
  • 83
  • 755
  • 726
1
if (!$(ui.newHeader).length)

or

if (!$(ui.newHeader)[0])
A. Wolff
  • 73,242
  • 9
  • 90
  • 149
1

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

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