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
  • 32,822
  • 74
  • 219
  • 400

1 Answers1

1

Use getElementsByClassName()

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

if(elements.length){
    Galleria.run(".showcase");
}
AmmarCSE
  • 29,061
  • 5
  • 39
  • 52