[재질문] a태그의 href 가져오기~ 채택완료
one9601
4년 전
조회 2,701
안녕하세요 재질문입니다 ㅠㅠ
안되가지구..ㅎ..
필터 or each를 통해서 url에 a태그의 href값을 포함하고 있다면
그의 부모인 depth2에게 active값을 부여하고 싶습니다
그런데 잘 안되네요 ㅠㅠㅠ
</p>
<p><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></p>
<p>
문제점이..뭘까요??
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
4년 전
일단...
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')))
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인