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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -