I am using font awesome 'plus' icon on expandable categories list items. When they are in expanded state i want to show a 'minus' sign'
HTML
<ul id="category-tabs"> <li><a href="javascript:void"><i class="fa fa-fw"></i>Category 1</a> <ul> <li><a href="javascript:void">item 1</a></li> <li><a href="javascript:void">item 2</a></li> <li><a href="javascript:void">item 3</a></li> </ul> </li> </ul>
Jquery
$('#category-tabs li a').click(function(){ $(this).next('ul').slideToggle('500'); });
In order to do this whilst retaining the <input> element, you must put the Font Awesome glyph outside of the <input> and then simply position it on top. Then simply add some CSS to make the whole button clickable.
You can place Font Awesome icons just about anywhere using the CSS Prefix fa and the icon's name. Font Awesome is designed to be used with inline elements (we like the <i> tag for brevity, but using a <span> is more semantically correct). icon If you change the font-size of the icon's container, the icon gets bigger.
Add Icons to HTML We recommend using <i> element with the Font Awesome CSS classes for the style class for the style of icon you want to use and the icon name class with the fa- prefix for the icon you want to use.
It is as simple as putting Font Awesome icon on any button. The <i> tag and <span> tag are used widely to add icons on the webpages. To add any icons on the webpages, it needs the font-awesome link inside the head section. The font-awesome icon can be placed by using the fa prefix before the icon's name.
You can toggle the class of the i
element within the clicked anchor like
<i class="fa fa-plus-circle"></i>
then
$('#category-tabs li a').click(function(){ $(this).next('ul').slideToggle('500'); $(this).find('i').toggleClass('fa-plus-circle fa-minus-circle') });
Demo: Fiddle
Simply call jQuery's toggleClass()
on the i
element contained within your a
element(s) to toggle either the plus and minus icons:
...click(function() { $(this).find('i').toggleClass('fa-minus-circle fa-plus-circle'); });
Note that this assumes that a class of fa-plus-circle
is added to your i
element by default.
JSFiddle demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With