Class Selector (".class")

Selects all elements with the given class.

.class(class)

class StringA class to search for. An element can have multiple classes; only one of them must match.

For class selectors, jQuery uses JavaScript's native getElementsByClassName() function if the browser supports it.

Finds the element with the class "myClass".

JS
<div class="notMe">div class="notMe"</div>
<div class="myClass">div class="myClass"</div>
<span class="myClass">span class="myClass"</span>
CSS
div,
span {
  width: 120px;
  height: 40px;
  float: left;
  padding: 10px;
  margin: 10px;
  background-color: #eeeeee;
}
HTML
$(".myClass").css("border", "3px solid red");
DEMO

Finds the element with both "myclass" and "otherclass" classes.

JS
<div class="myclass">div class="notMe"</div>
<div class="myclass otherclass">div class="myClass"</div>
<span class="myclass otherclass">span class="myClass"</span>
CSS
div,
span {
  width: 120px;
  height: 40px;
  float: left;
  padding: 10px;
  margin: 10px;
  background-color: #eeeeee;
}
HTML
$(".myclass.otherclass").css("border", "13px solid red");
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)