I am just saying that I would never pass a variable with a string that started 
with anything other than an alpha-numeric value and have never see that done 
either.
 
I would never write
 
var string1 = "#This is string1";
var string2 = "$This is string2";
 
or 
 
<div class=".class" id="#id"></div>
 
A lot of languages use some type of non-alpha-numeric character, as part of 
it's structure so I would never try to mix them. Other people have to read and 
work with that code also and it could get confusing and/or misleading.
 
 
 
http://2whoa.com/dominate
 


--- On Sun, 8/17/08, Michael Geary <[EMAIL PROTECTED]> wrote:

From: Michael Geary <[EMAIL PROTECTED]>
Subject: [jQuery] Re: Var and a child
To: jquery-en@googlegroups.com
Date: Sunday, August 17, 2008, 11:31 PM



I'm afraid I don't follow you. We were talking about this line of code:
 

var myVar = "#testDiv";
 
That looks like your basic string assignment statement to me.
 
What is ugly about it, and how does it goes against your best practices?
 
Thanks,
 
-Mike




From: ripple






Ok, It's in my best practices, not to do something like that. It's just ugly 
coding.
 
But if your ok with it, then you run with it.

From: Michael Geary



The # you're referring to:
 
var myVar = "#testDiv";

is part of a string literal, not part of a variable name, so it's perfectly 
legal.




From: ripple






You can not declare a javascript var with a # as first char.
 
try:
 
var myVar = "testDiv";
$('#'+myVar+' .statusColor).css("background-color","#DBF18A");

Other than that it should work.

--- On Sun, 8/17/08, hubbs <[EMAIL PROTECTED]> wrote:

From: hubbs

I am trying to var to work as a selector along with an additional
class, but I must have something wrong.

var myVar = "#testDiv";
$(myVar
".statusColor").css("background-color","#DBF18A");

<div id="testDiv">
  <span class="statusColor">Test</span>
</div>

I need to select the child of the myVar, but the selector seems to be
incorrect.





      

Reply via email to