I have created a feature to copy abbreviation definitions when the clipboard icon is clicked. A tooltip displaying 'Copied' should appear after clicking the icon, but for some reason, it's not visible. Here's the code:
$(document).ready(function () {
/* COPY TO CLIPBOARD */
// click the icon
$(".copy-icon").on("click", function (e) {
e.preventDefault();
// Find the parent list item
let listItem = $(this).closest("li");
// Find the abbreviation and definition within the list item
let abbreviation = listItem.find("p").text();
// Create a temporary input element
let $temp = $("<input>");
$("body").append($temp);
$temp.val(abbreviation).select();
document.execCommand("copy");
$temp.remove();
// Show the tooltip
let tooltip = $("<span class='tooltip'>Copied</span>");
listItem.append(tooltip);
// Remove the tooltip after 1 second
setTimeout(function () {
tooltip.remove();
}, 1000);
});
});
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
overflow-y: scroll;
}
body {
font-family: "Poppins", sans-serif;
background-color: #f0f0f0; /* Background color for the body */
}
/* Centering content */
.center {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
/* Container for the abbreviations list */
.container {
display: grid;
grid-template-columns: repeat(2, 1fr); /* Two columns for two rows */
gap: 20px; /* Adjust the gap as needed */
justify-content: center; /* Center the columns horizontally */
font-family: "Poppins", sans-serif;
padding: 0 20px; /* Add padding to the sides */
}
/* Abbreviations list row */
.abbreviations-row {
list-style: none;
padding: 0;
}
/* Abbreviation list item */
.abbreviations-list li {
display: flex;
align-items: center;
background-color: #fff; /* Background color for list items */
border: 1px solid #ccc; /* Border for list items */
border-radius: 8px; /* Rounded corners for list items */
margin: 10px;
padding: 10px;
position: relative;
}
/* Copy icon */
.copy-icon {
color: #2a7475;
font-size: 24px;
margin-right: 10px; /* Spacing between icon and text */
cursor: pointer;
}
.copy-icon:hover {
transform: translateY(-4px);
opacity: 1;
}
.abbreviations-list li {
position: relative; /* Add this line to set a non-static position */
/* ... Other styles ... */
}
.tooltip {
position: absolute;
top: -30%;
left: 50%;
transform: translateX(-50%);
background: #373737;
padding: 10px 15px;
color: #fff;
font-size: 14px;
border-radius: 4px;
letter-spacing: 1px;
opacity: 0;
z-index: 1; /* Ensure tooltip appears above other elements */
transition: opacity 0.3s ease-in-out;
}
.tooltip.appear {
animation: appear 1s ease;
}
@keyframes appear {
0% {
opacity: 0;
}
20% {
transform: translateY(10px);
opacity: 1;
}
80% {
transform: translateY(0px);
opacity: 1;
}
100% {
opacity: 0;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Abbreviations List</title>
<link
href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css?family=Poppins&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="header">
<h3>Abbreviations List</h3>
</div>
<div class="center">
<div class="container">
<div class="abbreviations-row">
<ul class="abbreviations-list">
<li>
<span class="tooltip">Copied</span>
<i class="material-icons copy-icon">content_copy</i>
<p>ACR, American College of Rheumatology criteria</p>
</li>
<li>
<span class="tooltip">Copied</span>
<i class="material-icons copy-icon">content_copy</i>
<p>AE, adverse event</p>
</li>
<li>
<span class="tooltip">Copied</span>
<i class="material-icons copy-icon">content_copy</i>
<p>AS, ankylosing spondylitis</p>
</li>
<!-- Add more abbreviations as needed -->
</ul>
</div>
<div class="abbreviations-row">
<ul class="abbreviations-list">
<li>
<span class="tooltip">Copied</span>
<i class="material-icons copy-icon">content_copy</i>
<p>
ACR 20/50/70, ≥20/≥50/≥70% response in the American College of
Rheumatology criteria
</p>
</li>
<li>
<span class="tooltip">Copied</span>
<i class="material-icons copy-icon">content_copy</i>
<p>API, abbreviated prescribing information</p>
</li>
<li>
<span class="tooltip">Copied</span>
<i class="material-icons copy-icon">content_copy</i>
<p>ASAS, Assessment of SpondyloArthritis international Society</p>
</li>
<!-- Add more abbreviations as needed -->
</ul>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</body>
</html>
I've consulted chatgpt regarding the issue, and according to it, there seems to be nothing wrong with the code, and the tooltip should be visible.