JSFiddle - React, Tailwind, and code Playground

by gabrieleromanato

HTML

<p id="test">abcdefgh</p>
<button id="run">Chop</button>

JavaScript

if(typeof String.prototype.chop !== 'function') {
    
    String.prototype.chop = function() {
    
      var str = this.substring(1, this.length - 1);

      return str;
    }
}
        
        
var btn = document.querySelector('#run'),
    test = document.querySelector('#test');


btn.addEventListener('click', function() {
    
    var text = test.firstChild.nodeValue;
    test.innerHTML = text.chop();
    
}, false);