In the below code I'm tried to create a dynamic menu (here it's written as static). when you click any where on the menu it will alert.
document.getElementById("rightMenu").addEventListener("click",function(){
alert("oh you clicked on right Menu");
});
ul,li{
list-style:none;
}
#prof-name {
margin-top: 10%;
padding-right: 0 ! important;
}
<ul id="rightMenu" class="user-profile">
<li class="topmenu rtopmenu-display-event" id="prof-name">
<a href="javascript:void(0)"><span class=" ico fa fa-user"></span><span id="user-name">Hello afsal khan</span><span class="fa fa-caret-down"></span></a>
<ul class="profile-menu" id="profile-menu">
<li><a href="http://qmsadm.local/profile"><span class="ico fa fa-user"></span><span>Profile</span></a></li>
<li><a href="http://qmsadm.local/password/change"><span class="ico fa fa-key" style ="margin-right:7px;"></span>Change Password</a></li>
<li><a href="http://qmsadm.local/logout"><span class="ico fa fa-sign-out"></span>Logout</a></li>
</ul>
</li>
</ul>
but the problem I'm facing is that it is alerting event if you are clicked on right side of the menu.
I have tried padding-right: 0 ! important;
,but which is not working
, it's not possible to set a specific width to menu because it's generating dynamically.
How can I fix this problem?
Your UL element is a block-level element, so if you inspect it you can see that it's 100% wide.
Either set it to display: inline-block; or give it some specific width.
fiddle