CSS Question

onclick div with glyphicon does not work when clicking icon

I got a menu that shows when the user click a "button", so i got the code below. It works when the user click in the div, but not when clicking on the icon in the span, can anybody explain me why? I have tried several combinations but never seem to be able to get it to work properly.

.dropbtn {
background-color: #888677;
color: white;
padding: 10px 30px 10px 30px;
font-size: 22px;
display: table;
margin: 0 auto
function getMenu() {
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {

<div id="myDropdown">
my menu

<div style="border:0px;z-index:1000;" class="dropbtn" onclick="getMenu()" >
<a onclick="getMenu()">
<span class="fa fa-bars">test</span>

Answer Source

Without seeing the getMenu() function its hard to say. It seems odd that you have the onclick on both the div and the anchor. If the onclick is triggered from the div, then you shouldn't need the anchor at all i would have thought

If I was doing this myself I might try something like this:


    <span id="menu_button_1" class="menu_button">
       <i class="fa fa-bars" aria-hidden="true"></i> Menu
    <ul class="sub_menu" id="sub_menu1">
      <li class="sub_menu_item">
        <i class="fa fa-square" aria-hidden="true"></i> Item




Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download