JavaScript

[DOM_Element] JS - className 속성 ★★★ = 요소의 클래스명 반환/설정. (= className속성 = 클래스네임)

Element.className = 'class names' : 기존에 class가 없으면 추가해 넣고, 있으면 기존 것을 변경.

※ Element.classList.add('class names') : 기존 class에 새로운 클래스를 추가.


className 예제

 

<style>

.box {

  width: 300px;

  height: 100px;

  line-height:100px;

  background-color: tomato;

  text-align: center;

  font-size: 25px;

  color: white;

  margin-bottom: 10px;

}

</style>


<div id="hz">

   홈짱닷컴 Homzzang.com

</div>


<button onclick="homzzang()">클릭</button>


<script>

function homzzang() {

  document.getElementById("hz").className = "box";

}

</script>

 

결과보기

 

 

방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
DOM_Attribute JS - nodemap.item() 메서드 -
DOM_Attribute JS - nodemap.length -
DOM_Attribute JS - nodemap.removeNamedItem() 메서드 -
DOM_Attribute JS - nodemap.setNamedItem() 메서드 -
DOM_Attribute JS - attr.appendChild() 메서드 - 사용금지
DOM_Attribute JS - attr.attributes - 사용금지
DOM_Attribute JS - attr.baseURI - 사용금지
DOM_Attribute JS - attr.childNodes - 사용금지
DOM_Attribute JS - attr.cloneNode() 메서드 - 사용금지
DOM_Attribute JS - attr.firstChild -
DOM_Attribute JS - attr.hasAttributes() 메서드 -
DOM_Attribute JS - attr.hasChildNodes -
DOM_Attribute JS - attr.insertBefore() 메서드 -
DOM_Attribute JS - attr.isEqualNode() 메서드 -
DOM_Attribute JS - attr.isSameNode() 메서드 -
27/89
목록
  • 채팅방
  • 필독
1. 채팅창 헤드에서 접속자 확인 2. 닉네임 클릭해 1:1 채팅 가능 3. 닉네임 클릭해 귓속말 가능 4. 닉네임 클릭해 호출하기 가능 5. 우하단 클릭해 환경 설정 가능 6. 의뢰글 작성 후 의뢰 상담 가능 7. 질문글 작성 후 질문 상담 가능 8. 채팅방에 개인정보 입력 금지 9. 채팅방에 광고 욕설 비방 금지
 홈  PC버전 로그인 일본어
웹디자인언어
서버관리언어
고급코딩언어
그누보드 1
제작의뢰
Q&A
커뮤니티 1
웹유틸
회원센터
홈짱 PC버전 로그인