javascript - Undefined is not a function -
currently learning native js , trying create interactive menu.
i'm trying run function once menubtn has been clicked have following error in console.
undefined not function
is global function issue here?
(function () { 'use strict'; var menubtn = document.getelementsbyclassname('btn-nav'); menubtn.addeventlistener('click', function() { console.log('clicked'); }, false); }());
html
<a href="#" class="btn-nav"> <span></span> <span>menu</span> <span></span> </a>
you trying add event listener nodelist. need single element.
var menubtn = document.getelementsbyclassname('btn-nav')[0];
Comments
Post a Comment