<!DOCTYPE html>
<html>
<head>
<style>
.code-box {
background-color: black;
color: white;
padding: 10px;
font-weight: bold;
}
.copy-button {
background-color: green;
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
font-weight: bold;
}
</style>
</head>
<body>
<button class="copy-button" onclick="copyCode()">Copy to Clipboard</button>
<div class="code-box">
Your code text here
</div>
<script>
function copyCode() {
const codeBox = document.querySelector('.code-box');
const codeText = codeBox.textContent;
navigator.clipboard.writeText(codeText)
.then(() => {
alert('Code copied to clipboard!');
})
.catch(err => {
console.error('Failed to copy code:', err);
});
}
</script>
</body>
</html>
<html>
<head>
<style>
.code-box {
background-color: black;
color: white;
padding: 10px;
font-weight: bold;
}
.copy-button {
background-color: green;
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
font-weight: bold;
}
</style>
</head>
<body>
<button class="copy-button" onclick="copyCode()">Copy to Clipboard</button>
<div class="code-box">
Your code text here
</div>
<script>
function copyCode() {
const codeBox = document.querySelector('.code-box');
const codeText = codeBox.textContent;
navigator.clipboard.writeText(codeText)
.then(() => {
alert('Code copied to clipboard!');
})
.catch(err => {
console.error('Failed to copy code:', err);
});
}
</script>
</body>
</html>