I\’m getting this error: Uncaught TypeError: Cannot call method \'match\' of undefined in my JavaScript. I\’m trying to write this without jQuery since it\’ll be the only js on the site.
My code is supposed to add a class, \”active\”, to the <a href=\"...> in the navigation that links to the current page.
I\’m guessing it might be the contentLoaded function?….source
Here\’s my code…(error occurs on line 9)…fiddle
(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)
Thanks!





Rating:
The post JavaScript…Cannot call method match of undefined appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/javascript-cannot-call-method-match-of-undefined.html
No comments:
Post a Comment