Remap toolbar button in custom.js

I’m trying to remap the “restart and run all” button to “run all cells” in R notebooks (since restarting kills the kernel).

I’ve used custom.js to remove that button and add a new one but the new button doesn’t actually do anything. Looking at it in Developer Tools shows identical markup – what am I missing?

Script:
// hide unsupported “Download As…” options and remap “Restart and Run All Cells for R notebooks”
require([‘base/js/events’,‘base/js/namespace’], function(events, IPython){
events.on(‘kernel_ready.Kernel’, function () {
$(‘li#download_pdf’).toggle();
$(‘li#download_webpdf’).toggle();
events.trigger(‘resize-header.Page’);
// if R kernel remap
var ker = getElementByXpath(“/html/body/div[@id=‘header’]/div[@id=‘menubar-container’]/div[@id=‘menubar’]/div[@id=‘menus’]/div[1]/p[@id=‘kernel_indicator’]/span[@class=‘kernel_indicator_name’]”);
if (ker.textContent == ‘R’){
alert(‘R kernel’);
// create button
var my_button = document.createElement(‘button’);
var my_i = document.createElement(‘i’);
my_button.setAttribute(“class”, “btn btn-default”);
my_button.setAttribute(“title”,“Run All Cells”);
my_button.setAttribute(“data-jupyter-action”,“jupyter-notebook:run-all-cells”);
my_i.setAttribute(“class”,“fa-forward fa”);
my_button.appendChild(my_i);

// JUPYTER method - same result
/*
var my_button = $(‘’)
.attr(‘class’,‘btn btn-default’)
.attr(‘title’,‘run all cells in the notebook’)
.attr(‘data-jupyter-action’,‘jupyter-notebook:run-all-cells’)
.attr(‘aria-label’, ‘Rull All’)
.insertAfter(‘div#run_int’)
.append(
$(‘’)
.addClass(‘fa-forward fa’)
)
// remove old button
const div = getElementByXpath(‘//div[@id=“run_int”]’);
div.removeChild(div.children[3]);
div.appendChild(my_button);

      //TODO: bind new button to action
    }

});
});

HTML shows new button, but doesn’t work:

Run ****

Any pointers would be appreciated.

TIA,
John