02.06.2024, 23:23
I've figured it out. For anyone else who needs to do this
It will appear in the left sidebar menu
Code:
document.addEventListener('DOMContentLoaded', function() {
var container = document.querySelector('.sidebar');
var ul = container.querySelector('ul');
var li = document.createElement("li");
var span = document.createElement("span");
span.classList.add('a');
var link = document.createElement("a");
link.href = "#";
link.textContent = "Nuevo Link";
span.appendChild(link);
li.addEventListener('click', HaceClick);
li.classList.add('level-1');
li.appendChild(span);
var referenceNode = ul.getElementsByTagName("li")[3]; // Insert before 3rd in the list
ul.insertBefore(li, referenceNode);
});
function HaceClick() {
alert('Ha pulsado Nuevo Link!');
}
It will appear in the left sidebar menu