I am new to asp.net and programming in general (this is my first question so please be patient with me).
I have encountered an issue with my initial project. The page contains multiple tiles, each following the same style. I want to include a dropdown menu with CRUD options (View, Update, Delete) on each tile. However, the problem arises when clicking the menu button - the dropdown menu always shows up on the first tile, regardless of where I click. I am looking for a way to display the menu on the specific tile I clicked on, enabling actions only on that particular element.
HTML:
<div class="tile-menu-dropdown">
<button onclick="tileMenu()" class="tile-menu-btn">
<i class="fas fa-ellipsis-v fa-2x" style="pointer-events: none;"></i>
</button>
<div id="tile-menu" class="tile-menu-content">
<button>View</button>
<button>Edit</button>
<button>Delete</button>
</div>
</div>
CSS:
.tiles .tile .tile-menu-btn {
position: absolute;
z-index: 1;
width: 50px;
height: 50px;
text-align: right;
top: 0;
right: 0;
padding-top: 14px;
padding-right: 14px;
background: none;
border: none;
outline: none;
font-size: 16px;
color: #ffffff;
transition: 0.3s;
transition-property: color;
cursor: pointer;
}
.tiles .tile .tile-menu-btn:hover {
color: #cd42e9;
}
.tile-menu-content {
display: none;
position: absolute;
background: #2F323A;
min-width: 80px;
border: 2px solid #cd42e9;
z-index: 1;
border-radius: 5px;
right: 0;
top: 50px;
}
.tile-menu-content button {
background: none;
border: none;
outline: none;
width: 100%;
color: #ffffff;
padding: 12px 16px;
text-decoration: none;
text-align: left;
font-size: 17px;
font-weight: 500;
font-family: 'Lato', sans-serif;
display: block;
}
.tile-menu-content button:hover {
color: #cd42e9;
background: #22242A;
}
.show {
display: block;
}
JavaScript:
function tileMenu() {
document.getElementById("tile-menu").classList.toggle("show");
}
window.onclick = function (event) {
if (!event.target.matches('.tile-menu-btn')) {
var dropdowns = document.getElementsByClassName("tile-menu-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}