How to customize jquery UI accordion icons?
Asked Answered
M

3

6

I want to customize the icons for the accordion. I found the page here http://jqueryui.com/accordion/#custom-icons But it seems to give a name of something there for the header and activeHeader.

How do you do this, if you just have a path to an image file?

Mistress answered 23/7, 2013 at 17:15 Comment(0)
Y
4

You would need to write some custom CSS to replace the jQuery UI icon that you plan to use. For example, in the case of the example code:

ui-icon-circle-arrow-e {background-image:url('path/to/my/images/filename.png') !important;}

Very similar to this SO question

Yoon answered 23/7, 2013 at 17:22 Comment(0)
R
34

Here's another option should you need the standard icons for another part of your project:

Working Example

JS

 $(function () {
     var icons = {
         header: "iconClosed",    // custom icon class
         activeHeader: "iconOpen" // custom icon class
     };
     $("#accordion").accordion({
         icons: icons
     });
 });

CSS

.ui-icon.iconOpen {
    background:url('YOUR Image HERE') no-repeat;
    background-size:20px;
    width:20px;
    height:20px;
}
.ui-icon.iconClosed {
    background:url('YOUR Image HERE') no-repeat -5px;
    background-size:30px;
    width:20px;
    height:20px;
}
Reunion answered 23/7, 2013 at 18:41 Comment(6)
why is the iconClosed background size 30px, and the first one only 20px?Mistress
@Mistress it just looked better with the particular images used.Reunion
@Mistress the size and aspect ratio of the original images used in the example are different.Reunion
doesn't work for me. i can see in conole log the css is loading but not showing in browser.Karole
@bonez I'm not sure what you mean. Can you share a fiddle showing the problem?Reunion
It may be helpful to know that older versions of jQuery UI use headerSelected instead of activeHeader.Tarpon
Y
4

You would need to write some custom CSS to replace the jQuery UI icon that you plan to use. For example, in the case of the example code:

ui-icon-circle-arrow-e {background-image:url('path/to/my/images/filename.png') !important;}

Very similar to this SO question

Yoon answered 23/7, 2013 at 17:22 Comment(0)
M
-1
$("#accordion").accordion({
  accordion: true,
  speed: 500,
  closedSign: '<img src="../../images/arrow-forward.png"/>',
  openedSign: '<img src="../../images/arrow-down.png"/>'
}); 
Meneses answered 30/3, 2015 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.