Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141456

onclick and eventListener for a dropdown menu not working

$
0
0

I have this Dropdown class in which I want to create new element that ,well you guessed it,works exactly like a drop down menu:

class Dropdown{
  constructor(name,element,classNa){
    this.classN = classNa;
      var x = new CElement(name,"div",dropdownHeaderStyle,"classN");
      x.display(element);
  }
  dropdown(mes){
    var z = new CElement(mes,"div",dropDownStyle,this.classN);
    z.display(".classN");

  }
}

(I have another class CElement that creates elements, using this parameters:value,elementType,elementStyle,classPara = "",and appends it with display funcion, there is no problem with it tho) the styling:

var dropDownStyle = "display:none;";
var show = "display:block;";

and the showFunction:

function showFunction(selector) {
  document.querySelector(selector).classList.toggle("show");
}

The problem happens when I add this bad boy:

 x.addEventListener('click',showFunction(".drpDown"));

or this:

x.onclick = showFunction(".drpDown");

It litteraly crashes,If I add that in the constructor, boom after that line nothing works... The ridiculous thing about this is that I am using another addEventListener('click' ... and that works.What am I doing wrong?


Viewing all articles
Browse latest Browse all 141456

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>