-1

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 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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: 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" ;)
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.