jQuery: The Write Less, Do More JavaScript Library

var $varname

View: New views
12 Messages — Rating Filter:   Alert me  

var $varname

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


what's the difference between:

var varname

var $varname

obviously I think 2nd is a jQuery variable?  If that's the case why
should I care and where is the docs on that?

Re: var $varname

by waseem sabjee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

its not really a jquery variable

in standard js you can say
var $myvar = "hello";
and
var myvar = "hello";

both will work the same

you can access jquery using either the $ or  JQuery
like

$("#myid").hide();
JQuery("#myid").hide();


in a line of the JQuery library code you would see something like

JQuery = window.JQuery = window.$ ...

your could say its like short hand code

instead of saying JQuery("") al the time you can just say $("")

On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschinkel@...> wrote:

what's the difference between:

var varname

var $varname

obviously I think 2nd is a jQuery variable?  If that's the case why
should I care and where is the docs on that?


Re: var $varname

by Michael Lawson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Just to addon to what Waseem here has said:

When you are using the default jQuery library, the variable $ is set to the value of jQuery, which creates a shortcut for you so that you don't have to keep typing jQuery everytime you want to access it, you can just type $.

cheers

Michael Lawson
Development Lead, Global Solutions, ibm.com
Phone: 1-276-206-8393
E-mail: mjlawson@...

'Examine my teachings critically, as a gold assayer would test gold. If you find they make sense, conform to your experience, and don't harm yourself or others, only then should you accept them.'

Inactive hide details for waseem sabjee ---07/02/2009 02:26:34 PM---its not really a jquery variablewaseem sabjee ---07/02/2009 02:26:34 PM---its not really a jquery variable


From:

waseem sabjee <waseemsabjee@...>

To:

jquery-en@...

Date:

07/02/2009 02:26 PM

Subject:

[jQuery] Re: var $varname





its not really a jquery variable

in standard js you can say
var $myvar = "hello";
and
var myvar = "hello";

both will work the same

you can access jquery using either the $ or  JQuery
like

$("#myid").hide();
JQuery("#myid").hide();


in a line of the JQuery library code you would see something like

JQuery = window.JQuery = window.$ ...

your could say its like short hand code

instead of saying JQuery("") al the time you can just say $("")

On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschinkel@...> wrote:

    what's the difference between:

    var varname

    var $varname

    obviously I think 2nd is a jQuery variable?  If that's the case why
    should I care and where is the docs on that?





Re: var $varname

by MorningZ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


"obviously I think 2nd is a jQuery variable?  If that's the case why
should I care and where is the docs on that? "

It just seems to be common practice by a lot of jQuery people smarter
than us to signify it's a jQuery object stored in that variable, it
has zero to do with jQuery itself per se




On Jul 2, 2:29 pm, Michael Lawson <mjlaw...@...> wrote:

> Just to addon to what Waseem here has said:
>
> When you are using the default jQuery library, the variable $ is set to the
> value of jQuery, which creates a shortcut for you so that you don't have to
> keep typing jQuery everytime you want to access it, you can just type $.
>
> cheers
>
> Michael Lawson
> Development Lead, Global Solutions, ibm.com
> Phone:  1-276-206-8393
> E-mail:  mjlaw...@...
>
> 'Examine my teachings critically, as a gold assayer would test gold. If you
> find they make sense, conform to your experience, and don't harm yourself
> or others, only then should you accept them.'
>
>   From:       waseem sabjee <waseemsab...@...>                                                                            
>
>   To:         jquery-en@...                                                                                        
>
>   Date:       07/02/2009 02:26 PM                                                                                                
>
>   Subject:    [jQuery] Re: var $varname                                                                                          
>
> its not really a jquery variable
>
> in standard js you can say
> var $myvar = "hello";
> and
> var myvar = "hello";
>
> both will work the same
>
> you can access jquery using either the $ or  JQuery
> like
>
> $("#myid").hide();
> JQuery("#myid").hide();
>
> in a line of the JQuery library code you would see something like
>
> JQuery = window.JQuery = window.$ ...
>
> your could say its like short hand code
>
> instead of saying JQuery("") al the time you can just say $("")
>
> On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschin...@...> wrote:
>
>   what's the difference between:
>
>   var varname
>
>   var $varname
>
>   obviously I think 2nd is a jQuery variable?  If that's the case why
>   should I care and where is the docs on that?
>
>  graycol.gif
> < 1KViewDownload
>
>  ecblank.gif
> < 1KViewDownload

Re: var $varname

by James-279 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Yep, as MorningZ said, it's a good practice to use it to differentiate
those that are storing a jQuery object.

$myDiv = $("#div_1");
$myDiv.hide();

It's easier to tell that you're working with a jQuery object.
Otherwise, it's just a regular variable.


On Jul 2, 8:51 am, MorningZ <morni...@...> wrote:

> "obviously I think 2nd is a jQuery variable?  If that's the case why
> should I care and where is the docs on that? "
>
> It just seems to be common practice by a lot of jQuery people smarter
> than us to signify it's a jQuery object stored in that variable, it
> has zero to do with jQuery itself per se
>
> On Jul 2, 2:29 pm, Michael Lawson <mjlaw...@...> wrote:
>
> > Just to addon to what Waseem here has said:
>
> > When you are using the default jQuery library, the variable $ is set to the
> > value of jQuery, which creates a shortcut for you so that you don't have to
> > keep typing jQuery everytime you want to access it, you can just type $.
>
> > cheers
>
> > Michael Lawson
> > Development Lead, Global Solutions, ibm.com
> > Phone:  1-276-206-8393
> > E-mail:  mjlaw...@...
>
> > 'Examine my teachings critically, as a gold assayer would test gold. If you
> > find they make sense, conform to your experience, and don't harm yourself
> > or others, only then should you accept them.'
>
> >   From:       waseem sabjee <waseemsab...@...>                                                                            
>
> >   To:         jquery-en@...                                                                                        
>
> >   Date:       07/02/2009 02:26 PM                                                                                                
>
> >   Subject:    [jQuery] Re: var $varname                                                                                          
>
> > its not really a jquery variable
>
> > in standard js you can say
> > var $myvar = "hello";
> > and
> > var myvar = "hello";
>
> > both will work the same
>
> > you can access jquery using either the $ or  JQuery
> > like
>
> > $("#myid").hide();
> > JQuery("#myid").hide();
>
> > in a line of the JQuery library code you would see something like
>
> > JQuery = window.JQuery = window.$ ...
>
> > your could say its like short hand code
>
> > instead of saying JQuery("") al the time you can just say $("")
>
> > On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschin...@...> wrote:
>
> >   what's the difference between:
>
> >   var varname
>
> >   var $varname
>
> >   obviously I think 2nd is a jQuery variable?  If that's the case why
> >   should I care and where is the docs on that?
>
> >  graycol.gif
> > < 1KViewDownload
>
> >  ecblank.gif
> > < 1KViewDownload
>
>

Re: var $varname

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I understand the shortcut.  But in this example, it appears to just be
a variable here.  So why did they even bother putting a $ in front of
it! ??

On Jul 2, 1:57 pm, James <james.gp....@...> wrote:

> Yep, as MorningZ said, it's a good practice to use it to differentiate
> those that are storing a jQuery object.
>
> $myDiv = $("#div_1");
> $myDiv.hide();
>
> It's easier to tell that you're working with a jQuery object.
> Otherwise, it's just a regular variable.
>
> On Jul 2, 8:51 am, MorningZ <morni...@...> wrote:
>
> > "obviously I think 2nd is a jQuery variable?  If that's the case why
> > should I care and where is the docs on that? "
>
> > It just seems to be common practice by a lot of jQuery people smarter
> > than us to signify it's a jQuery object stored in that variable, it
> > has zero to do with jQuery itself per se
>
> > On Jul 2, 2:29 pm, Michael Lawson <mjlaw...@...> wrote:
>
> > > Just to addon to what Waseem here has said:
>
> > > When you are using the default jQuery library, the variable $ is set to the
> > > value of jQuery, which creates a shortcut for you so that you don't have to
> > > keep typing jQuery everytime you want to access it, you can just type $.
>
> > > cheers
>
> > > Michael Lawson
> > > Development Lead, Global Solutions, ibm.com
> > > Phone:  1-276-206-8393
> > > E-mail:  mjlaw...@...
>
> > > 'Examine my teachings critically, as a gold assayer would test gold. If you
> > > find they make sense, conform to your experience, and don't harm yourself
> > > or others, only then should you accept them.'
>
> > >   From:       waseem sabjee <waseemsab...@...>                                                                            
>
> > >   To:         jquery-en@...                                                                                        
>
> > >   Date:       07/02/2009 02:26 PM                                                                                                
>
> > >   Subject:    [jQuery] Re: var $varname                                                                                          
>
> > > its not really a jquery variable
>
> > > in standard js you can say
> > > var $myvar = "hello";
> > > and
> > > var myvar = "hello";
>
> > > both will work the same
>
> > > you can access jquery using either the $ or  JQuery
> > > like
>
> > > $("#myid").hide();
> > > JQuery("#myid").hide();
>
> > > in a line of the JQuery library code you would see something like
>
> > > JQuery = window.JQuery = window.$ ...
>
> > > your could say its like short hand code
>
> > > instead of saying JQuery("") al the time you can just say $("")
>
> > > On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschin...@...> wrote:
>
> > >   what's the difference between:
>
> > >   var varname
>
> > >   var $varname
>
> > >   obviously I think 2nd is a jQuery variable?  If that's the case why
> > >   should I care and where is the docs on that?
>
> > >  graycol.gif
> > > < 1KViewDownload
>
> > >  ecblank.gif
> > > < 1KViewDownload

Re: var $varname

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Ah!  makes sense.  Because a lot of times I can't distinguish between
something in plain JavaScript and something that is a jQuery object.
Good to know.  I'll make sure I do the same once I start really
getting on board with the jQuery syntax.  It's a VERY good practice on
variables and so I wonder is there a "Best Practices For jQuery" on
the jquery site that I'm missing?  that would be awesome if there
was.  If not, how about someone start one and have it be either
moderated or have the best practices come straight from the jQuery
team.  Accept request to put in a new standard and have the team
approve/disapprove.

this kind of stuff would help people like me tremendously to help me
ramp up quicker for newbies like me who wonder wtf is going on when
things like this are in place such as the example question I just
proposed.

On Jul 2, 1:57 pm, James <james.gp....@...> wrote:

> Yep, as MorningZ said, it's a good practice to use it to differentiate
> those that are storing a jQuery object.
>
> $myDiv = $("#div_1");
> $myDiv.hide();
>
> It's easier to tell that you're working with a jQuery object.
> Otherwise, it's just a regular variable.
>
> On Jul 2, 8:51 am, MorningZ <morni...@...> wrote:
>
> > "obviously I think 2nd is a jQuery variable?  If that's the case why
> > should I care and where is the docs on that? "
>
> > It just seems to be common practice by a lot of jQuery people smarter
> > than us to signify it's a jQuery object stored in that variable, it
> > has zero to do with jQuery itself per se
>
> > On Jul 2, 2:29 pm, Michael Lawson <mjlaw...@...> wrote:
>
> > > Just to addon to what Waseem here has said:
>
> > > When you are using the default jQuery library, the variable $ is set to the
> > > value of jQuery, which creates a shortcut for you so that you don't have to
> > > keep typing jQuery everytime you want to access it, you can just type $.
>
> > > cheers
>
> > > Michael Lawson
> > > Development Lead, Global Solutions, ibm.com
> > > Phone:  1-276-206-8393
> > > E-mail:  mjlaw...@...
>
> > > 'Examine my teachings critically, as a gold assayer would test gold. If you
> > > find they make sense, conform to your experience, and don't harm yourself
> > > or others, only then should you accept them.'
>
> > >   From:       waseem sabjee <waseemsab...@...>                                                                            
>
> > >   To:         jquery-en@...                                                                                        
>
> > >   Date:       07/02/2009 02:26 PM                                                                                                
>
> > >   Subject:    [jQuery] Re: var $varname                                                                                          
>
> > > its not really a jquery variable
>
> > > in standard js you can say
> > > var $myvar = "hello";
> > > and
> > > var myvar = "hello";
>
> > > both will work the same
>
> > > you can access jquery using either the $ or  JQuery
> > > like
>
> > > $("#myid").hide();
> > > JQuery("#myid").hide();
>
> > > in a line of the JQuery library code you would see something like
>
> > > JQuery = window.JQuery = window.$ ...
>
> > > your could say its like short hand code
>
> > > instead of saying JQuery("") al the time you can just say $("")
>
> > > On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschin...@...> wrote:
>
> > >   what's the difference between:
>
> > >   var varname
>
> > >   var $varname
>
> > >   obviously I think 2nd is a jQuery variable?  If that's the case why
> > >   should I care and where is the docs on that?
>
> > >  graycol.gif
> > > < 1KViewDownload
>
> > >  ecblank.gif
> > > < 1KViewDownload

Re: var $varname

by James-279 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Not sure if there is a best practices page on the jquery domain
itself, but there are a lot of blog entries about this stuff. Sorry I
don't have any recommended links though. I just try to remember them
all. :p

Sorry my example was too simple, but it seems like you got the idea.

Like many programming languages, storing something that will be
accessed frequently is good to store/cache in a variable.
For example:
$fields = $("input[type=text][name^=field_][value!=test]");

Calling $("input[type=text][name^=field_][value!=test]") everytime you
want to work with it will hit jQuery harder since it has to walk
through the DOM everytime to look for matching elements.

$fields = $("input[type=text][name^=field_][value!=test]");
$fields.attr('disabled','disabled');
$fields.each(function() { ... });
$fields.val('');
$fields.removeAttr('disabled');

Also, it makes code easier to read. :)

On Jul 2, 9:04 am, expresso <dschin...@...> wrote:

> Ah!  makes sense.  Because a lot of times I can't distinguish between
> something in plain JavaScript and something that is a jQuery object.
> Good to know.  I'll make sure I do the same once I start really
> getting on board with the jQuery syntax.  It's a VERY good practice on
> variables and so I wonder is there a "Best Practices For jQuery" on
> the jquery site that I'm missing?  that would be awesome if there
> was.  If not, how about someone start one and have it be either
> moderated or have the best practices come straight from the jQuery
> team.  Accept request to put in a new standard and have the team
> approve/disapprove.
>
> this kind of stuff would help people like me tremendously to help me
> ramp up quicker for newbies like me who wonder wtf is going on when
> things like this are in place such as the example question I just
> proposed.
>
> On Jul 2, 1:57 pm, James <james.gp....@...> wrote:
>
> > Yep, as MorningZ said, it's a good practice to use it to differentiate
> > those that are storing a jQuery object.
>
> > $myDiv = $("#div_1");
> > $myDiv.hide();
>
> > It's easier to tell that you're working with a jQuery object.
> > Otherwise, it's just a regular variable.
>
> > On Jul 2, 8:51 am, MorningZ <morni...@...> wrote:
>
> > > "obviously I think 2nd is a jQuery variable?  If that's the case why
> > > should I care and where is the docs on that? "
>
> > > It just seems to be common practice by a lot of jQuery people smarter
> > > than us to signify it's a jQuery object stored in that variable, it
> > > has zero to do with jQuery itself per se
>
> > > On Jul 2, 2:29 pm, Michael Lawson <mjlaw...@...> wrote:
>
> > > > Just to addon to what Waseem here has said:
>
> > > > When you are using the default jQuery library, the variable $ is set to the
> > > > value of jQuery, which creates a shortcut for you so that you don't have to
> > > > keep typing jQuery everytime you want to access it, you can just type $.
>
> > > > cheers
>
> > > > Michael Lawson
> > > > Development Lead, Global Solutions, ibm.com
> > > > Phone:  1-276-206-8393
> > > > E-mail:  mjlaw...@...
>
> > > > 'Examine my teachings critically, as a gold assayer would test gold. If you
> > > > find they make sense, conform to your experience, and don't harm yourself
> > > > or others, only then should you accept them.'
>
> > > >   From:       waseem sabjee <waseemsab...@...>                                                                            
>
> > > >   To:         jquery-en@...                                                                                        
>
> > > >   Date:       07/02/2009 02:26 PM                                                                                                
>
> > > >   Subject:    [jQuery] Re: var $varname                                                                                          
>
> > > > its not really a jquery variable
>
> > > > in standard js you can say
> > > > var $myvar = "hello";
> > > > and
> > > > var myvar = "hello";
>
> > > > both will work the same
>
> > > > you can access jquery using either the $ or  JQuery
> > > > like
>
> > > > $("#myid").hide();
> > > > JQuery("#myid").hide();
>
> > > > in a line of the JQuery library code you would see something like
>
> > > > JQuery = window.JQuery = window.$ ...
>
> > > > your could say its like short hand code
>
> > > > instead of saying JQuery("") al the time you can just say $("")
>
> > > > On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschin...@...> wrote:
>
> > > >   what's the difference between:
>
> > > >   var varname
>
> > > >   var $varname
>
> > > >   obviously I think 2nd is a jQuery variable?  If that's the case why
> > > >   should I care and where is the docs on that?
>
> > > >  graycol.gif
> > > > < 1KViewDownload
>
> > > >  ecblank.gif
> > > > < 1KViewDownload
>
>

Re: var $varname

by north-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I also read about using $ or j if you're variable stores a jQuery
object.

Maybe this might sound stupid, but what if you first do something like
this:

var $showFeedback = $('#showFeedback' +spanIdNo);

(or var jShowFeedback = $('#showFeedback' +spanIdNo); respectively)

And if you then want to store the height of that element, do you use $
or j again (-> $showFeedbackHeight = $showFeedback.height();), or do
you use a "regular" variable name because it's not a jQuery object but
an attribute?

Maybe I'm just splitting hairs... :)

Cheers



On 2 Jul., 21:42, James <james.gp....@...> wrote:

> Not sure if there is a best practices page on the jquery domain
> itself, but there are a lot of blog entries about this stuff. Sorry I
> don't have any recommended links though. I just try to remember them
> all. :p
>
> Sorry my example was too simple, but it seems like you got the idea.
>
> Like many programming languages, storing something that will be
> accessed frequently is good to store/cache in a variable.
> For example:
> $fields = $("input[type=text][name^=field_][value!=test]");
>
> Calling $("input[type=text][name^=field_][value!=test]") everytime you
> want to work with it will hit jQuery harder since it has to walk
> through the DOM everytime to look for matching elements.
>
> $fields = $("input[type=text][name^=field_][value!=test]");
> $fields.attr('disabled','disabled');
> $fields.each(function() { ... });
> $fields.val('');
> $fields.removeAttr('disabled');
>
> Also, it makes code easier to read. :)
>
> On Jul 2, 9:04 am, expresso <dschin...@...> wrote:
>
> > Ah!  makes sense.  Because a lot of times I can't distinguish between
> > something in plain JavaScript and something that is a jQuery object.
> > Good to know.  I'll make sure I do the same once I start really
> > getting on board with the jQuery syntax.  It's a VERY good practice on
> > variables and so I wonder is there a "Best Practices For jQuery" on
> > the jquery site that I'm missing?  that would be awesome if there
> > was.  If not, how about someone start one and have it be either
> > moderated or have the best practices come straight from the jQuery
> > team.  Accept request to put in a new standard and have the team
> > approve/disapprove.
>
> > this kind of stuff would help people like me tremendously to help me
> > ramp up quicker for newbies like me who wonder wtf is going on when
> > things like this are in place such as the example question I just
> > proposed.
>
> > On Jul 2, 1:57 pm, James <james.gp....@...> wrote:
>
> > > Yep, as MorningZ said, it's a good practice to use it to differentiate
> > > those that are storing a jQuery object.
>
> > > $myDiv = $("#div_1");
> > > $myDiv.hide();
>
> > > It's easier to tell that you're working with a jQuery object.
> > > Otherwise, it's just a regular variable.
>
> > > On Jul 2, 8:51 am, MorningZ <morni...@...> wrote:
>
> > > > "obviously I think 2nd is a jQuery variable?  If that's the case why
> > > > should I care and where is the docs on that? "
>
> > > > It just seems to be common practice by a lot of jQuery people smarter
> > > > than us to signify it's a jQuery object stored in that variable, it
> > > > has zero to do with jQuery itself per se
>
> > > > On Jul 2, 2:29 pm, Michael Lawson <mjlaw...@...> wrote:
>
> > > > > Just to addon to what Waseem here has said:
>
> > > > > When you are using the default jQuery library, the variable $ is set to the
> > > > > value of jQuery, which creates a shortcut for you so that you don't have to
> > > > > keep typing jQuery everytime you want to access it, you can just type $.
>
> > > > > cheers
>
> > > > > Michael Lawson
> > > > > Development Lead, Global Solutions, ibm.com
> > > > > Phone:  1-276-206-8393
> > > > > E-mail:  mjlaw...@...
>
> > > > > 'Examine my teachings critically, as a gold assayer would test gold. If you
> > > > > find they make sense, conform to your experience, and don't harm yourself
> > > > > or others, only then should you accept them.'
>
> > > > >   From:       waseem sabjee <waseemsab...@...>                                                                            
>
> > > > >   To:         jquery-en@...                                                                                        
>
> > > > >   Date:       07/02/2009 02:26 PM                                                                                                
>
> > > > >   Subject:    [jQuery] Re: var $varname                                                                                          
>
> > > > > its not really a jquery variable
>
> > > > > in standard js you can say
> > > > > var $myvar = "hello";
> > > > > and
> > > > > var myvar = "hello";
>
> > > > > both will work the same
>
> > > > > you can access jquery using either the $ or  JQuery
> > > > > like
>
> > > > > $("#myid").hide();
> > > > > JQuery("#myid").hide();
>
> > > > > in a line of the JQuery library code you would see something like
>
> > > > > JQuery = window.JQuery = window.$ ...
>
> > > > > your could say its like short hand code
>
> > > > > instead of saying JQuery("") al the time you can just say $("")
>
> > > > > On Thu, Jul 2, 2009 at 8:18 PM, expresso <dschin...@...> wrote:
>
> > > > >   what's the difference between:
>
> > > > >   var varname
>
> > > > >   var $varname
>
> > > > >   obviously I think 2nd is a jQuery variable?  If that's the case why
> > > > >   should I care and where is the docs on that?
>
> > > > >  graycol.gif
> > > > > < 1KViewDownload
>
> > > > >  ecblank.gif
> > > > > < 1KViewDownload

Re: var $varname

by Karl Swedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 3, 2009, at 3:48 AM, olsch01 wrote:


I also read about using $ or j if you're variable stores a jQuery
object.

Maybe this might sound stupid, but what if you first do something like
this:

var $showFeedback = $('#showFeedback' +spanIdNo);

(or var jShowFeedback = $('#showFeedback' +spanIdNo); respectively)

And if you then want to store the height of that element, do you use $
or j again (-> $showFeedbackHeight = $showFeedback.height();), or do
you use a "regular" variable name because it's not a jQuery object but
an attribute?

If the value is numeric, which it is in this case, I wouldn't use the $ or j. I only use $variableName when the value is a jQuery object. 

var $showFeedback = $('#showFeedback' +spanIdNo);
var showFeedHeight = $showFeedback.height();

Of course, there isn't really a "right" way. It's just a convention (though a useful one). 

In case you're interested, this convention was first suggested by Michael Geary back in 2006. 

--Karl

____________
Karl Swedberg


Re: var $varname

by north-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Interesting. That was quite a while ago... :)

Thanks, Karl!


On 3 Jul., 15:55, Karl Swedberg <k...@...> wrote:

> On Jul 3, 2009, at 3:48 AM, olsch01 wrote:
>
>
>
> > I also read about using $ or j if you're variable stores a jQuery
> > object.
>
> > Maybe this might sound stupid, but what if you first do something like
> > this:
>
> > var $showFeedback = $('#showFeedback' +spanIdNo);
>
> > (or var jShowFeedback = $('#showFeedback' +spanIdNo); respectively)
>
> > And if you then want to store the height of that element, do you use $
> > or j again (-> $showFeedbackHeight = $showFeedback.height();), or do
> > you use a "regular" variable name because it's not a jQuery object but
> > an attribute?
>
> If the value is numeric, which it is in this case, I wouldn't use the  
> $ or j. I only use $variableName when the value is a jQuery object.
>
> var $showFeedback = $('#showFeedback' +spanIdNo);
> var showFeedHeight = $showFeedback.height();
>
> Of course, there isn't really a "right" way. It's just a convention  
> (though a useful one).
>
> In case you're interested, this convention was first suggested by  
> Michael Geary back in 2006.
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com

Re: var $varname

by Doug Nelson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I was convinced that this was some kind of faster, special-er variable
just for jQuery objects. Thanks to everyone on this thread for
clarifying.

> If the value is numeric, which it is in this case, I wouldn't use the  
> $ or j. I only use $variableName when the value is a jQuery object.