• 카테고리

    질문 & 답변
  • 세부 분야

    웹 개발

  • 해결 여부

    미해결

제이쿼리 click 함수 오류

23.08.20 17:43 작성 조회수 236

1

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="/css/style.css" />
  </head>
  <body>
    <script src="/js/code.jquery.com_jquery-3.7.0.js"></script>
    <script src="/js/custom.js"></script>
    <a class="show-btn" href="#">보이기</a>
    <a class="hide-btn" href="#">감추기</a>
    <div>Box</div>
  </body>
</html>

$(document).on('click', '.show-btn', function () {
  $('div').show();
});
$(document).on('click', '.hide-btn', function () {
  $('div').hide();
});

click함수로 쓸때 작동이 안되고 on함수로 썼을 때 작동이 되는데 이유가 무엇인가요?

답변 1

답변을 작성해보세요.

0

아래의 2가지 방법으로 하시면 작동 합니다.

image