Skip to content

Instantly share code, notes, and snippets.

@tjvantoll
Last active August 29, 2015 14:03
Show Gist options
  • Save tjvantoll/db83d89b0bafbeecaefe to your computer and use it in GitHub Desktop.
Save tjvantoll/db83d89b0bafbeecaefe to your computer and use it in GitHub Desktop.
Class Name Formatting Question

The following code adds a [placeholder] class name to the <body> element:

document.body.classList.add( "foo-bar" );

Question: How should the class name inserted at [placeholder] be formatted?


  • 1: foo-bar
  • 2: "foo-bar"
  • 3: “foo-bar”
  • 4: foo-bar
  • 5: "foo-bar"
  • 6: “foo-bar
@rdlauer
Copy link

rdlauer commented Jun 25, 2014

Personally, I would do 5.

@scottgonzalez
Copy link

#4. The context here is the actual class name, so it shouldn't be quoted. Because class names are meaningful values, they should be highlighted as code.

If you change the context slightly, then #5 is correct, e.g., We will pass "foo-bar" to classList.add().

@rauschma
Copy link

I would write:

The following code adds the class name "foo-bar" to the <body> element:

Or:

The following code adds the class whose name is "foo-bar" to the <body> element:

@codylindley
Copy link

7: class="foo-bar" that is exact and clear IMO

@tjvantoll
Copy link
Author

Thanks for the feedback everyone. At the end of the day I decided to go with #4 based on Scott's reasoning, but the fact that very smart people picked several different choices made me feel better about my confusion on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment