views:

45

answers:

1

Hello,

I was wondering about the different ways of using a JQuery function on a variable
like I know this one

$.DoThis(variable);

but is there a way to call it at the end like normal Javascript functions

variable.$.DoThis();

haha I know this sounds stupid but I need to ask somewhere. Thanks!

+1  A: 

You probably mean

$(variable).DoThis();

This implies that variable is

  • a plain DOM object (or an array of them)
  • a jQuery object (or an array of them)
  • a string that contains a jQuery selector
  • a string that contains HTML/XML markup
  • a callback function for the "DOM ready" event (not relevant in this case)

If it something else, all bets are off.

Tomalak
Also, this may not do the same thing; for example `$.isFunction(someObject)` is not at all the same as `$(someObject).isFunction()` (the latter will presumably always evaluate null as the parameter and return false).
JacobM
@JacobM: Yes, of course. But the OP mentioned `$.DoThis(variable)` himself, and seemed to ask "How do I make a jQuery object out of `variable`?". That's why I said "probably" ;)
Tomalak
Granted, but I think the OP has the expectation that making his variable into a jQuery object, and calling a jQuery function on it, will be the equivalent of calling a jQuery function and passing in his variable. That expectation, even if the variable is something that's convertible into a jQuery object as you describe, isn't valid. I'm not criticizing your answer here, I'm pointing out a flaw in (what I think is) the expectation of the OP.
JacobM