<!DOCTYPE html>
<html>
<head>
<title>Copy Text</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<section id="section1">
<h2>HTML Text</h2>
<p id="htmlText">This is the HTML text you want to copy.</p>
<button onclick="copyText('htmlText')">Copy HTML Text</button>
</section>
<section id="section2">
<h2>CSS Text</h2>
<p id="cssText">This is the CSS text you want to copy.</p>
<button onclick="copyText('cssText')">Copy CSS Text</button>
</section>
<section id="section3">
<h2>JS Text</h2>
<p id="jsText">This is the JS text you want to copy.</p>
<button onclick="copyText('jsText')">Copy JS Text</button>
</section>
<script src="script.js"></script>
<script>function copyText(id) {
var text = document.getElementById(id).innerText;
navigator.clipboard.writeText(text)
.then(function() {
alert('Text copied successfully!');
})
.catch(function(error) {
console.error('Unable to copy text: ', error);
});
}
</script>
</body>
</html>
HTML Text
This is the HTML text you want to copy.
CSS Text
This is the CSS text you want to copy.
JS Text
This is the JS text you want to copy.
No comments:
Post a Comment