Customize jquery ui selectmenu button icon

8.5k views Asked by At

What is the simplest way to customize the jquery ui selectmenu button icon (not the dropdown icons) with a custom icon NOT defined by default in the jQuery UI CSS Framework.

I see many examples for customizing jquery ui button icons using CSS, but not the selectmenu button icon.

<!doctype html>
<html lang="en">
<head>
  <title>SelectMenu Button Test</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

  <script>
  $(function() {
    $( "#buttonone" ).selectmenu({ icons: { button: "ui-icon-triangle-2-n-s" } });  
 //Replace with custom selectmenu button icon

    $( "#buttontwo" ).selectmenu({ icons: { button: "ui-icon-triangle-1-s" } }); 
//Replace with a second custom selectmenu button icon
  });
  </script>
</head>
<body>
     <select name="buttonone" id="buttonone">
            <option>All fields</option>
            <option>Field one</option>
            <option>Field two</option>
     </select>

     <select name="buttontwo" id="buttontwo">
            <option>All options</option>
            <option>Option one</option>
            <option>Option two</option>
     </select>

</body>
</html>
2

There are 2 answers

1
Casey Rule On BEST ANSWER

Yes, you can easily use custom styling on a button by supplying a custom class name, like this:

$( "#selectId" ).selectmenu({ icons: { button: "custom-icon" } });

Then you just add styling rules to your CSS for that class, like this:

.ui-state-default .ui-icon.custom-icon {
    background-image: url([your custom image]);
}

Simple JSFiddle example: http://jsfiddle.net/CaseyRule/f7q8sp43/1/

1
Noam L On

jQuery UI icons are all in a png file. Your theme image is This. You can download the library and then edit this file.

You can also create your own CSS rules and overwrite the icons. Just inspect the element to see what are his styles. The selectmenu styles are .ui-state-default .ui-icon for example.