Hello நண்பா 🥰
VIDEO
This HTML code creates a table with a single cell containing a code block. The code block has a "Copy" button that, when clicked, copies the text inside the code block to the clipboard.
Key Features Code Block : A pre element with the id "codeBlock" contains the code to be copied.
Copy Button : A button inside the table header with an onclick event that triggers the copyCode function.
Copy Functionality : The copyCode function uses the navigator.clipboard.writeText method to copy the code block text.
Example Use Case Replace "Suresh" in the codeBlock pre element with your desired code.
Click the "Copy" button to copy the code.
Paste the code wherever needed.
Advice Ensure the browser supports the navigator.clipboard API.
Adjust styles as needed for better integration with your website or application.
5 line code block white colour background
Code
Copy
<div>
<table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">
<thead>
<tr>
<th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left;">
Code
<button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px;">
Copy
</button>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); padding: 10px;">
<pre id="codeBlock" style="background-color: white; border-radius: 5px; color: black; font-family: monospace; max-height: 100px; overflow-y: auto; padding: 10px; white-space: pre-wrap;">suresh
</pre>
</td>
</tr>
</tbody>
</table>
<script>
function copyCode() {
var copyText = document.getElementById ("codeBlock").textContent;
navigator.clipboard.writeText (copyText).then(function() {
alert("Code copied to clipboard!");
}, function(err) {
alert("Failed to copy the code!");
});
}
</script>
</div>
Do not work the code block Download another one TXT format
5 line code block black colour background
Code
Copy
<div><br /></div><div><table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">
<thead>
<tr>
<th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left;">
Code
<button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px;">
Copy
</button>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); padding: 10px;">
<pre id="codeBlock" style="background-color: #333333 ; border-radius: 5px; color: white; font-family: monospace; max-height: 100px; overflow-y: auto; padding: 10px; white-space: pre-wrap;">suresh
</pre>
</td>
</tr>
</tbody>
</table>
<script>
function copyCode() {
var copyText = document.getElementById ("codeBlock").textContent;
navigator.clipboard.writeText (copyText).then(function() {
alert("Code copied to clipboard!");
}, function(err) {
alert("Failed to copy the code!");
});
}
</script>
</div><div><br /></div><div><br /></div><div><br /></div><div><br /></div>
Do not work the code block Download another one TXT format
Code block white colour background
Code
Copy
<table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">
<thead>
<tr>
<th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left; font-size: 12px;">
Code<button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px; font-size: 12px;">
Copy
</button>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color: #ffffff; border: 1px solid rgb(221, 221, 221); padding: 10px;">
<pre id="codeBlock" style="background-color: #ffffff; border-radius: 5px; color: black; font-family: monospace; font-size: 12px; padding: 10px; white-space: pre-wrap;">Suresh
</pre>
</td>
</tr>
</tbody>
</table>
<script>
function copyCode() {
var copyText = document.getElementById("codeBlock").textContent;
navigator.clipboard.writeText(copyText).then(function() {
alert("Code copied to clipboard!");
}, function(err) {
alert("Failed to copy the code!");
});
}
</script>
Do not work the code block Download another one TXT format
Code block black colour background
Code
Copy
<!--Table with Copy Button-->
<table style="border-collapse: collapse; margin: 20px 0px; position: relative; width: 100%;">
<thead>
<tr>
<th style="background-color: #f2f2f2; border: 1px solid rgb(221, 221, 221); padding: 10px; text-align: left;">
Code<button onclick="copyCode()" style="background-color: #4caf50; border-radius: 5px; border: none; color: white; cursor: pointer; float: right; padding: 5px 10px;">
Copy
</button>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color: #f9f9f9; border: 1px solid rgb(221, 221, 221); padding: 10px;">
<pre id="codeBlock" style="background-color: #333333; border-radius: 5px; color: white; font-family: monospace; padding: 10px; white-space: pre-wrap;">Suresh
</pre>
</td>
</tr>
</tbody>
</table>
<script>
function copyCode() {
var copyText = document.getElementById("codeBlock").textContent;
navigator.clipboard.writeText(copyText).then(function() {
alert("Code copied to clipboard!");
}, function(err) {
alert("Failed to copy the code!");
});
}
</script>
Do not work the code block Download another one TXT format
"This Content Sponsored by Genreviews.Online
Genreviews.online is One of the Review Portal Site
Website Link: https://genreviews.online/
Sponsor Content: #genreviews.online, #genreviews, #productreviews, #bestreviews, #reviewportal"