English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery .class class name selector

Specify the class name of the element to be selected

Said  .class   The selector selects all elements with the specified class.

It is declared before a string of one or more characters with a dot (.)

class属性用于为多个HTML元素设置特定样式。

The class attribute is used to set specific styles for multiple HTML elements.

HTML elements can also refer to multiple classes (see the example below).Note:

Do not start the class attribute with a number. It may cause exceptions in some browsers.

Syntax:

Select all elements with multiple class names of "myclass" and "otherclass":

$(".class")

Example
  Select all elements with the class "demo":-$(".myclass.otherclass").css("background
color", "yellow");
});/Test See‹

$(".demo").css("background

Example
  Select all <p> elements with the class "demo":-$(".myclass.otherclass").css("background
color", "yellow");
});/Test See‹

$("p.demo").css("background

Example
  $("document").ready(function(){-$(".myclass.otherclass").css("background
color", "yellow");
});/Test See‹

Parameter ValueParameters
Descriptionclass

Specify the class name of the element to be selected