Unable to set default value on Twitter

Bookmarks work well when clicked, but selecting a default tab when loading a window is not possible. Javascript works, no errors, but nothing happens. Any ideas?

<head> <link href="/assets/bootstrap.css?body=1" media="screen" rel="stylesheet" type="text/css" /> </head> <script> //<![CDATA[ window.onload=function () { $('#client_tab2').tab(); }; //]]> </script> <ul class='nav nav-tabs' id='tab'> <li><a href="#client_tab1" data-toggle="tab">General</a></li> <li><a href="#client_tab2" data-toggle="tab">Applications</a></li> <li><a href="#client_tab3" data-toggle="tab">Family</a></li> <li><a href="#client_tab4" data-toggle="tab">Memos</a></li> </ul> <form accept-charset="UTF-8" action="/clients/4512" class="simple_form client tab-content" id="edit_client_4512" method="post" novalidate="novalidate"> <div class='tab-pane active' id='client_tab1'> <legend>General Information</legend> </div> <div class='tab-pane' id='client_tab2'> <legend>Application Information</legend> </div> <div class='tab-pane' id='client_tab3'> <legend>Family</legend> </div> <div class='tab-pane' id='client_tab4'> <legend>Memos</legend> </div> </form> 
+6
source share
2 answers

Your selector is wrong, try like this:

 $(window).load(function(){ $('#tab a[href="#client_tab2"]').tab('show'); }); 

Demo: http://jsfiddle.net/TjjKE/

+10
source

You can also set the default tab as active only <li class="active"><a href="#whatever">....</a></li> , and then on the corresponding tab <div id="whatever" class="tab-pane active">..</div> and eliminate the need for more JS. look this

+9
source

Source: https://habr.com/ru/post/914063/


All Articles