开发者

Trying to toggle between two icons

开发者 https://www.devze.com 2023-01-21 11:06 出处:网络
I initiate two buttons (I\'m using the JQuery built in CSS themeroller): $( \".u开发者_Go百科pArrow\" ).button({ icons: {secondary:\'ui-icon-circle-arrow-n\'} });

I initiate two buttons (I'm using the JQuery built in CSS themeroller):

$( ".u开发者_Go百科pArrow" ).button({ icons: {secondary:'ui-icon-circle-arrow-n'} });
$( ".downArrow" ).button({ icons: {secondary:'ui-icon-circle-arrow-s'} });

I want to be able to toggle between these two icons when clicking the same button, and somehow switch between the .upArrow class and .downArrow class. I'm not sure how. I'd appreciate any help.


Since you're working with jQuery UI buttons, you can change the icon option with the toggle() function.

$('#button').toggle(function(){
    $(this).button('option', 'icons', {secondary:'ui-icon-circle-arrow-n'});
}, function(){
    $(this).button('option', 'icons', {secondary:'ui-icon-circle-arrow-s'});
});


You can use the .toggleClass() method of jQuery. You don't necessarily need to take away the other class, just use CSS to your advantage to override the other class' settings:

$('#foo').toggleClass(className, addOrRemove);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号