Search code examples
javascriptsquarespace

Remove character from entire website using javascript


Is it possible to remove a character from an entire website using javascript? Ideally pure javascript without needing to link a library. I'm working with a site that uses an arrow (→) on some of the buttons and links that i'd like to get rid of. The template is locked so I need to hack my way there. Any help appreciated.


Solution

  • You can use a simple loop to find and replace arrow character in all links and buttons.

    /* Remove arrow from linkes */
    
    var allLinks = document.getElementsByTagName('a');
    
    for(var i=0; i<allLinks.length; i++) {
        allLinks[i].text = allLinks[i].text.replace('→', '');
    }
    
    var allButtons = document.getElementsByTagName('button');
    
    for(var i=0; i<allButtons.length; i++) {
        allButtons[i].innerText = allButtons[i].innerText.replace('→', '');
    } 
    <button name="btn_arrow">
      Button arrow →
    </button>
    
    <a href="#">Link → Arrow</a>