.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>
게시글 목록
| 번호 | 제목 |
|---|---|
| 15854 |
jQuery
deferred.catch( failFilter )
|
| 15853 | |
| 15852 |
jQuery
.dblclick (handler)
|
| 15851 |
jQuery
제이쿼리 .data()
|
| 15849 |
jQuery
.css (propertyName)
|
| 15848 |
jQuery
.contextmenu( handler )
|
| 15847 |
jQuery
.contents()
|
| 15843 | |
| 15842 | |
| 15841 |
jQuery
.closest (selector)
|
| 15840 | |
| 15839 |
jQuery
제이쿼리 .click( handler )
|
| 15838 | |
| 15837 |
jQuery
제이쿼리 jQuery( ".class" )
|
| 15836 |
jQuery
제이쿼리 .children ([selector])
|
| 15835 |
jQuery
제이쿼리 jQuery ( ": checkbox")
|
| 15834 |
jQuery
제이쿼리 .change( handler )
|
| 15833 | |
| 15832 |
jQuery
제이쿼리 callbacks.locked ()
|
| 15831 |
jQuery
제이쿼리 callbacks.lock()
|
| 15830 | |
| 15829 | |
| 15828 |
jQuery
제이쿼리 callbacks.fired()
|
| 15826 | |
| 15825 | |
| 15824 |
jQuery
제이쿼리 callbacks.empty()
|
| 15823 |
PHP
rsa 암호화 클래스
|
| 15822 |
jQuery
제이쿼리 callbacks.disable ()
|
| 15821 | |
| 15820 |
jQuery
제이쿼리 .blur( handler )
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기