简体   繁体   中英

How to change tabs programmatically?

Im using http://www.menucool.com/tabbed-content to make tabs. Is there any way to change tabs by jquery/javascript ? i have tried $("tab1").click();

Created a fiddle for this- https://jsfiddle.net/6e3y9663/1/

Play with the selected class

$('.tabs').find('li.selected').removeClass('selected');//reset the tab buttons
$('#desiredTab').parent().addClass('selected');//or $('li a[href="#tab1"]').parent().addClass('selected'); - select the desired tab header
id = $('#desiredTab').attr('href');
$(id).siblings().hide();//reset the tab content
$(id).show();//$('#tab1').show();  -show the desired tab content

demo: https://jsfiddle.net/6e3y9663/5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM