JSFiddle - React, Tailwind, and code Playground

by anup1986

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<span class="the-span">Branch name</span>

JavaScript

function copyBranchName() {
  var text = document.getElementsByClassName('pr-header-branches')[0].firstElementChild.text;
  const el = document.createElement('input');
  el.value = text;
  document.body.appendChild(el);
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
  alert('Branch name copied ' + text);
};

var style = 'text-align: center; background: rgb(65,214,91); background: linear-gradient(90deg, rgba(65,214,91,1) 0%, rgba(68,157,17,1) 50%, rgba(35,144,23,1) 100%); color: white; width: 65px; height: 30px; padding: 5px; margin-left: 5px; border: none; border-radius: 3px;';

var button = document.createElement('button');
button.style = style;
button.innerText = 'Copy';
button.onclick = copyBranchName();

var branchSpan = document.querySelector('.the-span');
branchSpan.appendChild(button);