1

I am running a script as follows:

Galleria.run(".showcase");

The problem is when there is no element with class ".showcase" a message is rendered on the page.

How can I run this code if an element with class .showcase is found in the page?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

1 Answers1

1

Use getElementsByClassName()

var elements = document.getElementsByClassName('showcase');

if(elements.length){
    Galleria.run(".showcase");
}
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53