Search code examples
jqueryjquery-uijquery-ui-button

Add an image to the jquery button


I am wondering how to add an image to the jquery button. Till now I was using the jquery ui button in my project and I got custom images from the graphics team, so I would like to implement them.

submit.button({ icons: {primary:'ui-icon-trash'}, text: false })

How to add custom image to this jquery button?


Solution

  • <button>Trash</button>
    <style>
        .ui-button ​.ui-button-icon-primary {
            background: url('/my-custom-trash-image.png');
        }​
    </style>
    <script>
        $(function() {
            $('button').button({
                icons: {
                    primary: 'ui-icon-trash'
                },
                text: false
            });
        });
    </script>
    

    Unfortunately you do have to pass in a valid value for the primary icon even though it won't be used.

    Live Example - http://jsfiddle.net/aMVrz/