jQuery

[ETC] JQ - FAQ (자주묻는질문) 아코디언 메뉴

 

 

<script src="http://code.jquery.com/jquery-latest.js"></script>


<style>

.answer { display: none;  padding-bottom: 30px;  }

#faq-title { font-size: 25px; }

.faq-content { border-bottom: 1px solid #e0e0e0; }

.question { font-size: 19px; padding: 30px 0;  cursor: pointer; border: none; outline: none; background: none;  width: 100%;  text-align: left; }

.question:hover { color: #2962ff; }

[id$="-toggle"] { margin-right: 15px; }

</style>

 

<span id="faq-title">자주 묻는 질문(FAQ)</span>

<div class="faq-content">

    <button class="question" id="que-1"><span id="que-1-toggle">+</span><span>제목</span></button>

    <div class="answer" id="ans-1">내용</div>

</div>

<div class="faq-content">

    <button class="question" id="que-2"><span id="que-2-toggle">+</span><span>제목</span></button>

    <div class="answer" id="ans-2">내용</div>

</div>

 

 

<script>

const items = document.querySelectorAll('.question');

function openCloseAnswer() {

    const answerId = this.id.replace('que', 'ans');

    if(document.getElementById(answerId).style.display === 'block') {

      document.getElementById(answerId).style.display = 'none';

      document.getElementById(this.id + '-toggle').textContent = '+';

    } else {

      document.getElementById(answerId).style.display = 'block';

      document.getElementById(this.id + '-toggle').textContent = '-';

    }

}

items.forEach(item => item.addEventListener('click', openCloseAnswer));

document.getElementById('ans-1').style.display = 'block';

document.getElementById('que-1-toggle').textContent = '-';

</script>

 

결과보기 

※ 파란색 코드 : 특정 질문의 답변 먼저 펼쳐보이기

강아지망아지 님 + 서야 님 (201218) https://sir.kr/qa/390626

 


분류 제목
ETC JQ - 인풋계산값 자동입력 (= INPUT입력값 자동계산 = 필드계산결과 자동입력 = 연산자동입력) ★★★…
ETC JQ - draggable() 메서드 - 요소드래그이동 (= 요소이동 = 요소끌어이동 = Drag & Dro…
ETC JQ - 링크 (새창→ 현재창), (현재창→새창)으로 타겟 변경.
ETC JQ - 두 요소에 동시 입력 ★★★ (= Simultaneous Auto Multi Input)
ETC JQ - number_fommat() 구현. (= 넘버포맷 = 숫자 입력 시, 바로 천자리마다 쉼표 찍기)
ETC JQ - (입력・선택) 숫자 만큼 인풋 체크박스 체크.
ETC JQ - 스크롤 시, (배경색 변경 + 불투명도 조절) (= scroll background opacity …
ETC JQ - play(), pause() 메서드 - jquery 문법으로 처리하기
ETC JQ - eq() vs. get() 메서드 차이
ETC JQ - resizable() 메서드 - 요소 크기 재조정 (= 사이즈 변경 가능 = resizable메서드…
ETC JQ - (영문 년월일 → 숫자 년월일) 날짜시간 표기 변환.
ETC JQ - FAQ (자주묻는질문) 아코디언 메뉴
ETC JQ - 자식요소 너비를 부모요소 너비로 설정. (= 너버를 부모요소에 꽉차게 설정.)
ETC JQ - 요소 순서 랜덤 배치/정렬. ★★★★★
1/2
목록
 홈  PC버전 로그인 일본어
그누앞단언어 1
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티 1
웹유틸
회원센터
홈짱닷컴 PC버전 로그인