.class

选择所有与指定样式名相同的元素。

对于样式选择器而言,若浏览器支持的话,jQuery 会使用 JavaScript 原生的 getElementsByClassName() 函数来实现。

示例:

查找带有 "myClass" 样式的元素。

<!DOCTYPE html>
<html>
<head>
<style>
  div,span {
    width: 100px;
    height: 40px;
    float:left;
    padding: 10px;
    margin: 10px;
    background-color: #EEEEEE;
  }
  </style>
<script src="jquery.min.js"></script>
</head>
<body>

<div class="notMe">div class="notMe"</div>

  <div class="myClass">div class="myClass"</div>
  <span class="myClass">span class="myClass"</span>

<script>

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

</script>
</body>
</html>

演示:

示例:

查找既有 "myclass" 样式也有 "otherclass" 样式的元素。

<!DOCTYPE html>
<html>
<head>
<style>
  div,span {
    width: 100px;
    height: 40px;
    float:left;
    padding: 10px;
    margin: 10px;
    background-color: #EEEEEE;
  }
  </style>
<script src="jquery.min.js"></script>
</head>
<body>

<div class="myclass">div class="notMe"</div>

  <div class="myclass otherclass">div class="myClass"</div>
  <span class="myclass otherclass">span class="myClass"</span>

<script>

$(".myclass.otherclass").css("border","13px solid red");

</script>
</body>
</html>

演示: