document.hrefと同じhrefを持つリンクにClassを追加することは可能かどうか疑問に思っていますか?
試してみましたが、運がありませんでした。
if ($("a").attr("href") == document.location.href) {
$(this).addClass("active");
}
これは不可能ですか?
document.hrefと同じhrefを持つリンクにClassを追加することは可能かどうか疑問に思っていますか?
試してみましたが、運がありませんでした。
if ($("a").attr("href") == document.location.href) {
$(this).addClass("active");
}
これは不可能ですか?
$("a").filter(function() {
return this.href === document.location.href;
}).addClass("active");
動作するはずです。
$("a[href=" + document.location.href + "]").addClass("active");
(未検証)
document.location.href の代わりに window.location.href を試しましたか?