• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what name spacing to use for div id's and classes?

#1
[eluser]webmastergrumpy[/eluser]
What name spacing to use for div id's and classes?

Camel or _ or none at all?

#2
[eluser]webmastergrumpy[/eluser]
got a suggestion from a friend.

div id's _ and class -


#3
[eluser]skunkbad[/eluser]
A namespace is not the same as a naming convention, which is what you are asking about.

#4
[eluser]InsiteFX[/eluser]
Javascript does not like underscores so try to stay away from them by using the hyphen -

#5
[eluser]jmadsen[/eluser]
lol

I think he meant the "space between name parts": namespacing.

This was my smile for the day :-)

#6
[eluser]jmadsen[/eluser]
[quote author="InsiteFX" date="1340520022"]Javascript does not like underscores so try to stay away from them by using the hyphen -
[/quote]

what do you mean by that, exactly?

#7
[eluser]kanjimaster[/eluser]
As InsiteFX says, avoid underscores, but as to whether to use camel casing or hyphens, it makes little difference, just choose whichever you prefer and stick to it, or go with whatever the authors of any javascript library you're using do, or do the opposite so that you can tell your ids and classes from those that the library inserts.

There's not a single right answer to this, other than once you've chosen, be consistent.

#8
[eluser]InsiteFX[/eluser]
Javascript does not like underscores in css class names or id's.

Because support is so inconsistent between current browsers as well as older releases, authors are strongly advised to avoid using underscores in class and ID names. A common substitute is the hyphen character (-), as in:
Code:
.color-red {}

#9
[eluser]Aken[/eluser]
[quote author="InsiteFX" date="1340541246"]Javascript does not like underscores in css class names or id's.[/quote]

This is backwards. Javascript prefers underscores.

The most widely accepted, unofficial standard is to use underscores in IDs, and hyphens in class names.

http://stackoverflow.com/questions/16968...underlines

Beyond that, the naming conventions are your own personal preference.

#10
[eluser]CroNiX[/eluser]
Javascript and PHP are pretty much the same in that regard, as well as all other "languages". They don't like hyphens because that generally is a subtraction operation, so you can't use them in variable names, function names, etc. CSS doesn't care, as it's not a "language" and either hyphen or underscore will work fine, are are both valid/legal. Javascript and php don't care about hyphens in strings, like id's or classnames though.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.