After Clicked the button then paste it into NotePad or anywhere else for testing.
<div class="showcontent">
<h3>Write something in the input field and then click the button to copy the text.</h3>
<div class="tooltiprow">
<div class="tooltipinput">
<input type="text" id="text" placeholder="some text...">
</div>
<div class="tooltipcontent">
<button onclick="tooltip()">copy</button>
<div class="tooltiptext">
<span>Coppied text</span>
<div class="arrow">
</div>
</div>
</div>
</div>
<p>After Clicked the button then paste it into NotePad or anywhere else for testing.</p>
</div>
function tooltip(){
let tooltext=document.getElementsByClassName("tooltiptext");
//console.log(tooltext);//return collection1
tooltext[0].style.display="inline-block";
let input=document.getElementById("text");
console.log(input);
input.select();
navigator.clipboard.writeText(input.value);
setTimeout(function(){
tooltext[0].style.display='none';
},1500)
}
.tooltiprow{
display: flex;
align-items: center;
justify-content: center;
}
.tooltiprow input[type=text]{
padding: 8px 16px;
border-radius: 5px;
overflow: hidden;
margin-right: 8px;
font-size: 18px;
}
.tooltipcontent{
position: relative;
}
.tooltipcontent button{
padding: 8px 16px;
background-color:rgb(0, 255, 85);
color:white;
border: none;
border-radius: 10px;
font-size: 20px;
cursor: pointer;
}
.tooltipcontent button:hover{
background-color:rgb(0, 255, 123);
color:black;
}
.tooltiptext{
position: absolute;
white-space: nowrap;
top:-107%;
padding: 6px;
left: 50%;
transform: translate(-50%);
background-color: black;
color: white;
border-radius: 5px;
animation-name: ex;
animation-timing-function: ease-in-out;
animation-duration: 1s;
display: none;
}
@keyframes ex {
from{opacity: 0.4;}
to{opacity: 1;}
}
.arrow{
display:inline-block;
position: absolute;
top: 100%;
left: 50%;
transform: translate(-50%);
border-width: 8px;
border-style: solid;
border-color:black transparent transparent transparent;
}
@media screen and (max-width:350px) {
.tooltiprow{
flex-direction: column;
}
.tooltipinput{
margin-bottom: 15px;
}
}