목차

jQuery class Selector

  • description : jQuery class Selector
  • author : 오션
  • email : shlim@repia.com
  • lastupdate : 2021-06-02


The source of this article

jQuery class Selector

Example

“intro” 클래스를 가진 모든 요소를 선택합니다.

<body>
 
  <h1>Welcome to My Homepage</h1>
 
  <p class="intro">My name is Donald</p> <!-- underlined -->
  <p>I live in Duckburg</p>
 
  <div class="intro">My name is Dolly</div> <!-- underlined -->
  <p>I live in Duckburg.</p>
 
  <script>
    $(document).ready(function () {
      $('.intro').css('text-decoration', 'underline');
    })
  </script>
 
</body>

Definition and Usage

.class 선택자는 특정 클래스를 가진 모든 요소를 ​​선택합니다.

class는 HTML 요소의 클래스 속성(class attribute)을 나타냅니다.

클래스 속성은 여러 HTML 요소에 대한 특정 스타일을 설정하는 데 사용됩니다.

Note: 숫자로 클래스 속성을 시작하지 마십시오. 일부 브라우저에서는 문제가 발생할 수 있습니다.

Syntax

$(".class")


Parameter Description
class 필수입니다. 선택할 요소들의 클래스를 지정합니다.

Example

intro 클래스를 가진 모든 p 요소들을 선택합니다.
intro 클래스를 가진 모든 p 요소들을 선택하는 방법.

<body>
 
  <h1>Welcome to My Homepage</h1>
 
  <p class="intro">My name is Donald</p> <!-- bold text, darkgreen color -->
  <p>I live in Duckburg</p>
 
  <div class="intro">My name is Dolly</div>
  <p>I live in Duckburg.</p>
 
  <script>
    $(document).ready(function () {
      /* $('p.intro').css('color', 'darkgreen');
      $('p.intro').css('font-weight', 'bold'); */
      $('p.intro').css({
        color: 'darkgreen',
        fontWeight: 'bold',
      });
    });
  </script>
 
</body>