Using JavaScript to Remove Class in Joomla

Needed to remove a class from a Gantry Menu Particle, because I wanted to easily add “rel=”canonical””. I really hate when something simple in plain HTML becomes a headache in a CMS like Joomla. I probably went about this the hard way, but here is the method I came up with.

  • Use “Sourcerer” plug-in to put CSS in the page. This was in the article first, then the Gantry Menu Particle, and then JavaScript.
  • I used a Gantry Particle Menu, because it is easy to put in the “rel” tag.
  • Use “Sourcerer” plug-in to put Javascript in the page. I used the following two lines. First gets the ID of the module and then removing the class on the “nav” item.

    var element = document.getElementById(“module-menu-298-particle”).getElementsByClassName(“g-main-nav”)[0];
    element.classList.remove(“g-main-nav”);

Let me know if this helped you….

0 Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.