回答編集履歴
3
加筆
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
- `$(this).attr("href")` は、**href属性の文字列をそのまま**取得します。
|
28
28
|
|
29
|
-
- `this.href` は実際にリンクする先の**フルのURL**を取得できます。
|
29
|
+
- `$(this).prop("href")`(あるいは単純に `this.href`) は実際にリンクする先の**フルのURL**を取得できます。
|
30
30
|
|
31
31
|
|
32
32
|
|
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
console.log($("#link").attr("href")); // hoge.html
|
40
40
|
|
41
|
-
console.log($("#link").
|
41
|
+
console.log($("#link").prop("href")); // http://○○○.○○○/○○○/hoge.html
|
42
42
|
|
43
43
|
</script>
|
44
44
|
|
2
コードの修正
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
$(function(){
|
8
8
|
|
9
|
-
$("a").each(function(){
|
9
|
+
$(".side__navigation a").each(function(){
|
10
10
|
|
11
11
|
if(this.href == location.href) $(this).addClass("is_active");
|
12
12
|
|
1
誤字の修正
test
CHANGED
@@ -18,19 +18,15 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
以前の質問
|
21
|
+
以前の質問を拝見しましたが、`$(this).attr("href")` を使っていますね。
|
22
22
|
|
23
23
|
今回は `this.href` を使いました。
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
- `$(this).attr("href")` は、href属性の文字列をそのまま取得します。
|
27
|
+
- `$(this).attr("href")` は、**href属性の文字列をそのまま**取得します。
|
28
28
|
|
29
|
-
- `this.href` は実際にリンクする先のフルのURLを取得できます。
|
29
|
+
- `this.href` は実際にリンクする先の**フルのURL**を取得できます。
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
ですので、`this.href` を利用すれば、`location.href` との単純比較で現在URLと一致しているかどうか確認することが出来ます。
|
34
30
|
|
35
31
|
|
36
32
|
|
@@ -47,3 +43,7 @@
|
|
47
43
|
</script>
|
48
44
|
|
49
45
|
```
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
ですので、`this.href` を利用すれば `location.href` との単純比較で現在URLと一致しているかどうか確認することが出来ます。
|