.hasClass( className )
설명 : 일치하는 요소가 주어진 클래스에 지정되었는지 여부를 판별하십시오.
요소에는 둘 이상의 클래스가 할당되어있을 수 있습니다. HTML에서는 클래스 이름을 공백으로 구분하여 나타냅니다.
<div id="mydiv" class="foo bar"></div>
다른 클래스가있는 경우에도 클래스에 요소가 할당되면 이 .hasClass()메서드가 반환 true됩니다. 예를 들어 위의 HTML을 보면 다음과 같이 반환됩니다 true.
$( "#mydiv" ).hasClass( "foo" )
마찬가지로 :
$( "#mydiv" ).hasClass( "bar" )
이것이 반환하는 동안 false:
$( "#mydiv" ).hasClass( "quux" )
jQuery 1.12 / 2.2부터이 메소드는 SVG를 포함한 XML 문서를 지원한다.
예:
'selected'가 클래스로 포함 된 단락을 찾습니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>hasClass demo</title>
<style>
p {
margin: 8px;
font-size: 16px;
}
.selected {
color: red;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>This paragraph is black and is the first paragraph.</p>
<p class="selected">This paragraph is red and is the second paragraph.</p>
<div id="result1">First paragraph has selected class: </div>
<div id="result2">Second paragraph has selected class: </div>
<div id="result3">At least one paragraph has selected class: </div>
<script>
$( "#result1" ).append( $( "p:first" ).hasClass( "selected" ).toString() );
$( "#result2" ).append( $( "p:last" ).hasClass( "selected" ).toString() );
$( "#result3" ).append( $( "p" ).hasClass( "selected" ).toString() ) ;
</script>
</body>
</html>
게시글 목록
| 번호 | 제목 |
|---|---|
| 15819 |
jQuery
제이쿼리 jQuery( ":button" )
|
| 15818 | |
| 15817 | |
| 15816 | |
| 15815 | |
| 15814 | |
| 15813 | |
| 15812 | |
| 15811 | |
| 15810 | |
| 15809 |
jQuery
제이쿼리 .attr (attributeName)
|
| 15808 |
jQuery
제이쿼리 .appendTo( target )
|
| 15807 | |
| 15806 |
jQuery
animated selector
|
| 15805 | |
| 15804 |
jQuery
제이쿼리 andSelf()
|
| 15803 |
jQuery
제이쿼리 all selector
|
| 15802 |
jQuery
제이쿼리 .ajaxSuccess(handler)
|
| 15801 |
jQuery
.ajaxStop(handler )
|
| 15800 |
jQuery
.ajaxStart(handler )
|
| 15799 |
jQuery
.ajaxSend (handler )
|
| 15798 |
jQuery
제이쿼리 .ajaxError (handler)
|
| 15797 |
jQuery
제이쿼리 .ajaxComplete (handler)
|
| 15796 |
jQuery
제이쿼리 .after()
|
| 15792 | |
| 15791 |
jQuery
제이쿼리 .addBack ()
|
| 15790 |
jQuery
제이쿼리 .add (selector)
|
| 15789 | |
| 15788 | |
| 15787 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기