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

[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

 

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

분류 제목
ETC JQ - play(), pause() 메서드 - jquery 문법으로 처리하기
ETC JQ - eq() vs. get() 메서드 차이
ETC JQ - resizable() 메서드 - 요소 크기 재조정 (= 사이즈 변경 가능 = resizable메서드…
ETC JQ - (영문 년월일 → 숫자 년월일) 날짜시간 표기 변환.
ETC JQ - FAQ (자주묻는질문) 아코디언 메뉴
ETC JQ - 자식요소 너비를 부모요소 너비로 설정. (= 너버를 부모요소에 꽉차게 설정.)
ETC JQ - 요소 순서 랜덤 배치/정렬. ★★★★★
ETC JQ - fakeLoader(페이크로더) 효과 + 이미지 랜덤 인트로 페이지
ETC JQ - <li> 높이를 LI 요소 중 최대높이에 맞추기 설정 (= 가장 긴/높은 높이에 맞추기 = 높이 정…
ETC JQ - Uncaught TypeError: Cannot read properties of undefined…
bookmark JQ - 실렉트 리스트간 아이템 선택/해제 (추가/삭제/이동) (Move Items Between Two S…
jquery JQ - (1초/0.5초)이상 마우스버튼 누르고 있으면 숫자 증가 (= 마우스 클릭하고 있으면 숫자 증가 =…
jquery JQ - 콘텐츠를 일정 높이 기준으로 페이징 처리 (= 본문 내용을 일정 높이 단위로 페이지 처리) ※ 이전…
jquery JQ - <textarea> (텍스트에어리어) 입력 가능 최대 길이 설정 (= 글자수 카운트)
jquery JQ - 스크롤 시 비디오 동영상 자동재생 시작 (Scroll Video Autoplay)
jquery JQ - 동영상 제어 메서드 종류 - load(), play(), pause()
basic JQ - 쿠키 (Cookie) 사용법 - 생성/얻기/삭제
jquery JQ - $.fn (= jQuery.fn) 확장 - 사용자정의메서드 생성
jquery JQ - 모든 링크 주소를 특정 URL주소로 일괄 변경
jquery JQ - 입력된 값만 보이기 (= 입력값만 표시 = 입력값 없는 요소 숨기기)
15/15
목록
찾아주셔서 감사합니다. Since 2012