0

I want to execute function when button is clicked. Button is created using append() function.

I've tried using on but it is not working.

I trying to achieve zoom functionality. I've modified imgages-grid.js file in library. link of the library : https://github.com/taras-d/images-grid#images-grid

Here is the code I modified in file images-grid.js file :

ImagesGridModal.prototype.renderModal = function() {
        this.$modal = $('<div>', {
            class: 'imgs-grid-modal'
        }).append(
            $('<div>', {
                class: 'zoom-btn'
            }).append(
                $('<button id="ttt">', {
                    class: 'zoom'
                }).append("+")
            ).append(
                $('<button>', {
                }).append("-")
            )
        ).appendTo('body');
    }

And in another js file I am writing function for zoom in and out Right now I am just trying to print normal console.log("Executed");

Here is the code :

$("#ttt").on("click", function() {
    console.log("Executed");
});

What I want when + button is clicked image size should increase & when - is clicked it should decrease.

user2459780
  • 95
  • 1
  • 2
  • 8

1 Answers1

0

Base on source code(https://github.com/taras-d/images-grid/blob/master/src/images-grid.js) may be you should try this:

ImagesGridModal.prototype.renderModal = function () {
this.$modal = $('<div>', {
    class: 'imgs-grid-modal'
}).append(
    $('<div>', {
        class: 'zoom-btn'
    }).append(
        $('<button id="ttt">', {
            class: 'zoom',
            on: {
                load: this.onImageLoaded,
                click: function (event) {
                    console.log("Executed");
                }.bind(this)
            }
        }).append("+")
    ).append(
        $('<button>', {
        }).append("-")
    )
).appendTo('body');

}

Madjarov
  • 73
  • 1
  • 4