[재질문] a태그의 href 가져오기~

[재질문] a태그의 href 가져오기~

QA

[재질문] a태그의 href 가져오기~

답변 1

본문

안녕하세요 재질문입니다 ㅠㅠ

 

안되가지구..ㅎ..

 

필터 or each를 통해서 url에 a태그의 href값을 포함하고 있다면

그의 부모인 depth2에게 active값을 부여하고 싶습니다

 

그런데 잘 안되네요 ㅠㅠㅠ

 


<script>
  $(document).ready(function () {
 
    var url = window.location.href;
    $('#header .gnb .depth2 > a').filter(function () {
      if url.includes($(this).attr('href')) {
        $(this).parent(".depth2").addClass('active');
      }
    });
  });
</script>
or
<script>
  $(document).ready(function () {
 
    var url = window.location.href;
    $('#header .gnb .depth2 > a').each(function () {
      if url.includes($(this).attr('href')) {
        $(this).parent(".depth2").addClass('active');
      }
    });
  });
</script>

 

 

문제점이..뭘까요??

 

http://iden07.cafe24.com/bbs/board.php?bo_table=tl_notice04

이 질문에 댓글 쓰기 :

답변 1

일단...
Uncaught SyntaxError: Unexpected identifier
board.php?bo_table=tl_notice04:255 


if 문의 condition을 괄호로 감싸보세요
파이썬하고 헤깔리셨나요...?
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/if...else
if url.includes($(this).attr('href'))
if (url.includes($(this).attr('href')))

 

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 6
© SIRSOFT
현재 페이지 제일 처음으로