tags:

views:

19

answers:

2

I am trying to run a code but I get

$.uniform is undefined
[Break on this error] $.uniform.restore("#f_variedbyoperator"); 

How can I use jQuery, to detect if .uniform has been defined? And to signup the code to run after that.

+1  A: 

The same way you'd test any other property:

  • $.hasOwnProperty('uniform') (true if it is defined), or
  • typeof $.uniform === 'undefined' (true if it is not defined), or
  • !!$.uniform (true if it is a truthy value - anything other than undefined, null, 0, false, or '' - the empty string)

What do you mean "signup the code to run?"


var i = setInterval(function ()
{
    if ($.uniform)
    {
        clearInterval(i);
        $.uniform.restore("#f_variedbyoperator");
    }
}, 1000); // check for $.uniform every 1000 ms
Matt Ball
I want to run `$.uniform.restore("#f_variedbyoperator"); ` subscribed by some event after `$.uniform` has been defined.
Pentium10
@Pentium10: I assume you mean something like a repeated check, until it exists. See my edit
Matt Ball
repeating sounds good.
Pentium10
A: 

If all you want to do is check that an element exists, try:

if($('element').length)
{
  // exists!
}
Hollister
Not my down-vote (I'm anticipating this getting one), but this is *completely* unrelated to the question.
Nick Craver
He asked how to check if an element was defined. This is how. The question is confusing as it is. That's why I prefaced the answer with "if..."
Hollister
@Hollister - He wasn't asking about an element at all, the word "element" appears nowhere in the question :)
Nick Craver