Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Created June 9, 2013 14:17
Show Gist options
  • Select an option

  • Save jswhisperer/5743710 to your computer and use it in GitHub Desktop.

Select an option

Save jswhisperer/5743710 to your computer and use it in GitHub Desktop.
CSS classes without jquery
// get reference to DOM element
var el = document.querySelector(".main-content");
//----Adding a class------
/* jQuery */
$(el).addClass("someClass");
/* native equivalent */
el.classList.add("someClass");
//----Removing a class-----
/* jQuery */
$(el).removeClass("someClass");
/* native equivalent */
el.classList.remove("someClass");
//----Does it have class---
/* jQuery */
if($(el).hasClass("someClass"));
/* native equivalent */
if(el.classList.contains("someClass"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment