javascriptvariablesdocument-readydefinedfotorama

Accessing a Declared Variable


Good time. How do I access a declared variable? I declare like this:

$ (document) .ready (function () {

    var fotorama = $fotoramaDiv.data ('fotorama');

$ (document) .on ('click', '.btn-del-model', function (e) {

console.log (e);
console.log (fotorama); // Uncaught ReferenceError: fotorama is not defined

   });

});

The button with the ".btn-del-model" class is dynamically created. Tell me how to access the "fotorama" variable?


Solution

  • You need to assign value in fotoramaDiv from DOM using class syntax or id.

    // for example
    const fotoramaDiv = document.querySelector('.yourClassName');