Selecting specific tab on page load

4 replies · opened Dec 15, 2017

IicefieldDec 15, 2017

Having difficulty showing specific tab on a page I'm developing. To demonstrate issue, I've slimmed down your tabs.html to the following, and added a bit of JS at the bottom to attempt setting a specific tab on page load. Can't get any tab but the first to show. Could you provide some guidance? Thanks.


	
	

	
	
- 
	
- 
	
- 
	
- 
	
- 
	
- 
	
- 

	
- 
	

	
	Tabs | Canvas

	
	

		
		

			

				

					
					

						

							
								
- [](#tabs-1)
								
- [Nunc tincidunt](#tabs-2)
								
- [Proin dolor](#tabs-3)
								
- [Aenean lacinia](#tabs-4)
							

							

								
									Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.
								
								
									Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.
								
								
									
Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.

									Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.
								
								
									Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.
								

							

						
					

				

			

		

	

	
	

	
	
	

	
	

	
		jQuery(document).ready( function($){
			$('[href="#tabs-3"]').tab('show');				// By name (without parent)
//			$('#ul-tab-1 [href="#tabs-3"]').tab('show');	// By name (with parent)
//			$('#tab-1 [href="#tabs-3"]').tab('show');		// By name (with ancester)
// 			$('#tab-1 a:first').tab('show');				// Select first tab
// 			$('#tab-1 a:last').tab('show');					// Select last tab
// 			$('#tab-1 li:eq(2) a').tab('show');				// Select third tab (0-indexed)
		});
	
SSemicolon WebSTAFFDec 15, 2017

Hello,

This functionality is already included within Canvas. Simply consider adding the data-active="2" Attribute to the .tabs Element to activate the 2nd Tab on Load. Example code:


	
		
- [Tab 1](#tab-1)
		
- [Tab 2](#tab-2)
		
- [Tab 3](#tab-3)
	

	

		
			Tab Content 1
		
		
			Tab Content 2
		
		
			Tab Content 3
		

	

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

IicefieldDec 15, 2017

So foobar.tab('show') is specific to bootstrap tabs.

Using foobar.click() on Canvas tabs works as I need it.

Hope this helps someone in the future.

IicefieldDec 15, 2017

Want to set the tab dynamically depending on some other PHP//JS values. Using the info in the next message in this thread, I was able to get the desired tab displaying on page reload using the foobar.click() technique.

SSemicolon WebSTAFFDec 15, 2017

Hello,

This is Possible too! Add the id="tabs-1" Attribute to the .tabs Element and then add the following JS Code at the bottom of the Page just after the js/functions.js JS File Linking:


	jQuery(window).on( 'load', function(){
		jQuery( '#tabs-1' ).tabs( 'option', 'active', 1 );
	});

Remember that the value 1 here represents the index value of the Tab starting from 0. So the 1 value activates the 2nd Tab.

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard