Search code examples
javascriptjquerygalleria

How to apply toggleClass to an element? Galleria


I try to build my custom theme, based on "Galleria theme Classic", but I'm straggling to trigger class on my button, I think, I miss something,

   this.addElement('play').appendChild('container','play');
   var g = this;
   this.$('play').text('Play').bind('mouseup', function() {
            g.playToggle();
            g.toggleClass("highlight"); // - This line don't work
});

I get error @TypeError: g.toggleClass is not a function@


Solution

  • It looks like you're calling toggleClass on the wrong element, or the element is not jQuery wrapped (not quite clear from posted code). Try this:

    $(g).toggleClass('highlight');
    

    Or this:

    g.$('play').toggleClass('highlight');