Skip to content

Instantly share code, notes, and snippets.

@aosteraas
Created March 13, 2017 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aosteraas/e3a1e4506a74c9a4086b60939e40030f to your computer and use it in GitHub Desktop.
Save aosteraas/e3a1e4506a74c9a4086b60939e40030f to your computer and use it in GitHub Desktop.
// I think the best way to show how the choice will influence what you do is in html
// Normally when writing HTML you would use double quotes for whatever classes/attributes you apply
// but here, in JS, we are starting the string with double quotes so we *must* use single quotes instead
var myElement = "<div class='class-something'></div>";
var myClass = "snd-nds";
// If you want to use a variable as the class name you need to use single quotes like we did before but then use
// concatenation to join it together
// ** **
var anotherElement = "<div class='" + myClass + "'></div>";
// The inverse will also work
var andAnotherOne = '<div class="' + myClass + '"></div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment