jQuery: The Write Less, Do More JavaScript Library

Selectors/class

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

.class

Matches all elements with the given class.
Arguments:
classString
A class to search for. An element can have multiple classes, one of them must match.

Examples:
Finds the element with the class "myClass".

$(".myClass").css("border","3px solid red");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="../jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $(".myClass").css("border","3px solid red");
  });
  </script>
  <style>
  div,span {
    width: 150px;
    height: 60px;
    float:left;
    padding: 10px;
    margin: 10px;
    background-color: #EEEEEE;
  }
  </style>
</head>
<body>
  <div class="notMe">div class="notMe"</div>
  <div class="myClass">div class="myClass"</div>
  <span class="myClass">span class="myClass"</span>
</body>
</html>

NameType