CodeIgniter Forums
what name spacing to use for div id's and classes? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: what name spacing to use for div id's and classes? (/showthread.php?tid=52719)

Pages: 1 2


what name spacing to use for div id's and classes? - El Forum - 06-23-2012

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

Camel or _ or none at all?


what name spacing to use for div id's and classes? - El Forum - 06-23-2012

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

div id's _ and class -




what name spacing to use for div id's and classes? - El Forum - 06-23-2012

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


what name spacing to use for div id's and classes? - El Forum - 06-23-2012

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



what name spacing to use for div id's and classes? - El Forum - 06-23-2012

[eluser]jmadsen[/eluser]
lol

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

This was my smile for the day :-)


what name spacing to use for div id's and classes? - El Forum - 06-24-2012

[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?


what name spacing to use for div id's and classes? - El Forum - 06-24-2012

[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.


what name spacing to use for div id's and classes? - El Forum - 06-24-2012

[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 {}



what name spacing to use for div id's and classes? - El Forum - 06-24-2012

[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/1696864/naming-class-and-id-html-attributes-dashes-vs-underlines

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


what name spacing to use for div id's and classes? - El Forum - 06-24-2012

[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.