JavaScript w2ui - toolbar change button image on click w2ui grid change toolbar,w2ui grid toolbar

I am using w2ui. I have a toolbar with one button. This button has the icon-image "icon-delete".

When I click on the button, I want it to change the icon-image to "icon-add", but my code doesn't work.

toolbar: {
    items: [{
        type: 'button',
        id: 'hide',
        caption: 'Menü',
        img: 'icon-delete'
    }],
    onClick: function (target, data) {
        if (target == 'hide') {
            this.items.img('icon-add');
        }
    }
}
Answer:1

You can use toolbar.set() method to update toolbar button icon. So in your onClick event do the following:

onClick: function (target, data) {
   this.set(target, { icon: 'new_icon' });
}

See more here: http://w2ui.com/web/docs/w2toolbar.set

Answer:2

I created a hidden button "show" with the "icon-add" image. when the button "hide" is clicked, it get hidden and the button "show" get shown.

toolbar: {
            name: 'toolbar',
            items: [
                { type: 'button',  id: 'hide', caption: 'Menü', img: 'icon-delete' },
                { type: 'button',  id: 'show', hidden: 'true', caption: 'Menü', img: 'icon-add' }
            ],
            onClick: function (target, data) {
                if (target == 'hide' ) {w2ui['layout'].toggle('left', window.instant);

                                        this.hide('hide');
                                        this.show('show');
                                        }
                if (target == 'show' ) {w2ui['layout'].toggle('left', window.instant);

                                        this.hide('show');
                                        this.show('hide');
                                        }                       

            }
        }
Answer:3

Im using wordpress theme that has different parts like for example footer.php or header.php. What I want to do is reload one part of the whole page using jquery so that the whole page does not refresh....

Im using wordpress theme that has different parts like for example footer.php or header.php. What I want to do is reload one part of the whole page using jquery so that the whole page does not refresh....

I've written the following code to understand class like implementations and closures in JavaScript. 1 function Person(name) { this.Name = name; console.log("Person Fired!!"); (function ...

I've written the following code to understand class like implementations and closures in JavaScript. 1 function Person(name) { this.Name = name; console.log("Person Fired!!"); (function ...

  1. javascript class closures

I have an html page with some inputs and textareas. I want them to have qTip with different texts. Here is my attempt First I add a qTip to every element, $('input, textarea').each(function() { ...

I have an html page with some inputs and textareas. I want them to have qTip with different texts. Here is my attempt First I add a qTip to every element, $('input, textarea').each(function() { ...

This is actually two question. I was playing around with the .eq method in jquery and decided to test it out using jsfiddle. What puzzles me is that when I supply an index that is obviously out of ...

This is actually two question. I was playing around with the .eq method in jquery and decided to test it out using jsfiddle. What puzzles me is that when I supply an index that is obviously out of ...