2

I would like, ideally in the php file of a menu override, to add role="menu-item" i.e. direct links to another location, in a Joomla 3x (and 4x) menu.

Is this possible, or do I need to use JavaScript? (No jQuery, please).

1 Answer 1

2

After much experimentation I'm pretty sure it's not possible to achieve this without Javascript, but I did manage it this way:

I added this code to the menu's main php file (about line 53 in the default.php override):

    if ($item!=parent)
    {
        $class .= ' single';
    }

Then in the template.js added this:

    let single = [...document.querySelectorAll('li > a')];
    [].forEach.call(single, function(sg) {
    sg.setAttribute("role", "menuitem");
    })
    let singleb = [...document.querySelectorAll('li.single > button > a')];
    [].forEach.call(singleb, function(sgb) {
    sgb.setAttribute("role", "menuitem");
    })

I'm using buttons in my navigation but if you're not you can leave out the second half of this code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.