このエラーが発生します:Uncaught TypeError: Cannot call method 'match' of undefined
JavaScriptで。jQueryがサイトで唯一のjsになるので、これをjQueryなしで書き込もうとしています。
私のコードは<a href="...>
、現在のページにリンクするナビゲーションのに「アクティブ」というクラスを追加することになっています。
関数かもしれないとcontentLoaded
思いますか?....ソース
これが私のコードです...(9行目でエラーが発生します)...フィドル
(function(window, document, undefined) { contentLoaded(window, function() {
var page = document.location.pathname.match(/[A-z]+$/)[0],
nav_anchors = document.getElementsByTagName('header')[0]
.getElementsByTagName('nav')[0]
.getElementsByTagName('a');
for(i in nav_anchors)
if(nav_anchors[i].href.match(/[A-z]+$/)[0] = page) //LINE 9 <-- Error
nav_anchors[i].classList.add('active');
})
})(this, this.document)
ありがとう!