Home Add Code Box Skip to main content

Add Code Box





HTML
<!-- Your HTML content -->
<!-- Code Box -->
<div class="K2_CBox">
  <div class="CB_Heading">
    <span>HTML</span>
    <button class="C_box_main" id="copy1" onclick="copyC('copy1','code1')">
      <i class="CBox_icn"></i>
    </button>
  </div>

  <!-- Add Your HTML code Here -->
  <div id="code1">
    <pre><p>This is a simple HTML code</p></pre>
  </div>
</div>
<!-- JavaScript -->
<script>
  function copyC(sourceId, targetId) {
    const sourceElement = document.getElementById(sourceId);
    const targetElement = document.getElementById(targetId);

    const range = document.createRange();
    range.selectNodeContents(targetElement);
    const selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(range);

    document.execCommand('copy');
    selection.removeAllRanges();

    // Additional logic or feedback after copying
  }
</script>

<!-- CSS Styles -->
<style>
  .K2_CBox .C_box_main .CBox_icn {
    display: none; /* Hide the icon by default */
  }

  .K2_CBox .C_box_main:hover .CBox_icn {
    display: inline-block; /* Display icon on button hover */
  }
</style>
bbb
<!-- Your HTML content --> <!-- Code Box --> <div class="K2_CBox"> <div class="CB_Heading"> <span>HTML</span> <button class="C_box_main" id="copy1" onclick="copyC('copy1','code1')"> <i class="CBox_icn"></i> </button> </div> <!-- Add Your HTML code Here --> <div id="code1"> <pre><p>This is a simple HTML code</p></pre> </div> </div> <!-- JavaScript --> <script> function copyC(sourceId, targetId) { const sourceElement = document.getElementById(sourceId); const targetElement = document.getElementById(targetId); const range = document.createRange(); range.selectNodeContents(targetElement); const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); selection.removeAllRanges(); // Additional logic or feedback after copying } </script> <!-- CSS Styles --> <style> .K2_CBox .C_box_main .CBox_icn { display: none; /* Hide the icon by default */ } .K2_CBox .C_box_main:hover .CBox_icn { display: inline-block; /* Display icon on button hover */ } </style>

upper ☝code ko apne </body>tag HTMLtheme me paste kar de or apne edit post me html me ja kar only itna 👇code paste kare jo niche diya gaha hia sath me app id change kar de


you can add how many code box u needed only you all need to change is 

<span>HTML</span> to <span>HTML1</span>
<button id='copy2' class='C_box_main' onclick="copyC('copy2','code2')">
 <div id='code2'>




HTML1
<!--Your HTML content-->
<!--Code Box-->
<div class="K2_CBox">
  <div class="CB_Heading">
    <span>HTML</span>
    <button class="C_box_main" id="copy1" onclick="copyC('copy1','code1')">
      <i class="CBox_icn"></i>
    </button>
  </div>

  <!--Add Your HTML code Here-->
  <div id="code1">
    <pre>&lt;p&gt;This is a simple HTML code&lt;/p&gt;</pre>
  </div>

Comments

Lazy Loading Example Preloaded Image Another Preloaded Image