• 회원가입
  • 로그인
  • 구글아이디로 로그인

[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

 


분류 제목
Property JQ - jquery 속성 - 제이쿼리버전번호 (= jQuery버전번호 = JQ버전번호)
Property JQ - jQuery.fx.interval 속성 - 애니메이션 점화빈도를 밀리초단위로 변경
Property JQ - jQuery.fx.off 속성 - 애니메이션 비활성화/활성화
Property JQ - jQuery.support 속성 - 브라우저 기능/버그 표시 속성모음 (jQuery 내부용)
Property JQ - length 속성 ★ - 객체의 요소개수 (= length속성 = 렝스속성) ※ 입력 내용 일정 길…
ETC JQ - 인풋계산값 자동입력 (= INPUT입력값 자동계산 = 필드계산결과 자동입력 = 연산자동입력) ★★★…
Misc JQ - 검색필터링 (= 일치값 찾기)
ETC JQ - draggable() 메서드 - 요소드래그이동 (= 요소이동 = 요소끌어이동 = Drag & Dro…
jquery JQ - 얼럿창 (= 다이얼로그창)
basic JQ - JS변수 vs JQuery변수
basic JQ - 링크클릭이동 : href속성 + replace()메서드
Examples JQ - 리스트랜덤 (= 목록랜덤)
Selector JQ - this 선택자 - 현재 요소 선택. (= 디스 선택자)
Examples JQ - (부모요소・자식요소) 데이터값・입력값 변경
ETC JQ - 링크 (새창→ 현재창), (현재창→새창)으로 타겟 변경.
ETC JQ - 두 요소에 동시 입력 ★★★ (= Simultaneous Auto Multi Input)
ETC JQ - number_fommat() 구현. (= 넘버포맷 = 숫자 입력 시, 바로 천자리마다 쉼표 찍기)
ETC JQ - (입력・선택) 숫자 만큼 인풋 체크박스 체크.
ETC JQ - 스크롤 시, (배경색 변경 + 불투명도 조절) (= scroll background opacity …
ETC JQ - play(), pause() 메서드 - jquery 문법으로 처리하기
14/15
목록
찾아주셔서 감사합니다. Since 2012