Html/css/js/copy button

   <!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>

☝️👇
Copy Text

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

Audio file

Gujarati TTS Audio Player Gujarati TTS Audio Player Convert to Audio Your browser does not support the au...