채택완료

자바스크립트 주소 이동 이벤트

게시판에서 tr 태그를 클릭하면, 제목의 주소로 이동하게 자바스크립트를 작성했습니다.

화면 너비가 767px 이하일 때만 작동하게 하려면 어떻게 하나요?

 

Copy
const boardTableRow = document.querySelectorAll('.tbl_head01 tr');

 

boardTableRow.forEach(function(tr) {
  tr.addEventListener('click', function(e) {
    window.location.href = this.querySelector('.bo_tit_link').getAttribute('href');
  });
});

답변 1개

채택된 답변
+20 포인트

Copy
const boardTableRow = document.querySelectorAll('.tbl_head01 tr');
 
boardTableRow.forEach(function(tr) {
  tr.addEventListener('click', function(e) {
    if ($(window).width() <= 767) {
      window.location.href = this.querySelector('.bo_tit_link').getAttribute('href');
    }
  });
});

답변을 작성하려면 로그인이 필요합니다.