adding jquery ui icon to a submit button

14,412

Solution 1

You can change your HTML like this:

<button type="submit">
    Add Driver
</button>

And then update your script like this:

$('button[type=submit]').button({icons: {primary: 'ui-icon-circle-plus'}}).click(function (event) {
    event.preventDefault();
});

Demo: http://jsfiddle.net/mh5Pu/

Solution 2

this should work

$( "input[type=submit]" ).button({icons: {primary: "ui-icon-circle-plus"}})      .click(function( event ) {
event.preventDefault();
});

or you set it afterwards:

$( "input[type=submit]" ).button( "option", "icons", { primary: "ui-icon-circle-plus", secondary: "<your_second_icon>" } );

Here is an working example.

Solution 3

Look at the examples on http://jqueryui.com/button/#icons (specifically the icons).

Instead of using a submit input, try using a button.

Here's a modified version of the icon only button with ui-icon-circle-plus:

<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"     role="button" aria-disabled="false" title="Button with icon only">
<span class="ui-button-icon-primary ui-icon ui-icon-circle-plus"></span>
<span class="ui-button-text">Button with icon only</span>
</button>
Share:
14,412
Robert Martens
Author by

Robert Martens

Updated on August 21, 2022

Comments

  • Robert Martens
    Robert Martens over 1 year

    I have the following code for a submit button my page: The html markup is:

    <td align="Right"><input type="submit" value="Add Driver" ></td>
    

    and the jquery is:

    $( "input[type=submit]" ).button().click(function( event ) {
    event.preventDefault();
    });
    

    How would I add a ui icon to the above, specifically the ui-icon-circle-plus

  • Laokoon
    Laokoon about 11 years
    look at this: jsfiddle.net/Kfubw you also have an error in your HTML syntax: this is the correct HTML: <td align="Right"><input type="submit" value="Add Driver" /></td>
  • Beda Schmid
    Beda Schmid over 2 years
    I don't see any icon on the fiddle. It just is a text button.