Abhinav
Abhinav

Reputation: 89

How to autoclick my tab link with hash parameter

I have 4 tabs on my web page . But on page load always first tab is opened . I want to open other tabs on page load with some hash parameter in url Here is my code :

<ul class="tab-links">
    <li class="active"><a href="#tab1"> tab1 </a></li>
    <li><a href="#tab2"> tab2 </a></li>
    <li><a href="#tab3"> tab2 </a></li>
    <li><a href="#tab4"> tab2 </a></li>
</ul>

<div class="tab-content">
    <div id="tab1"  class="tab active">

    </div>

    <div id="tab2" class="tab">

    </div>

    <div id="tab3"  class="tab">

    </div>

    <div id="tab4"  class="tab">

    </div>

Upvotes: 0

Views: 223

Answers (1)

Debugger
Debugger

Reputation: 491

you can achieve it by php something like that. pas an attribute on the click of a link eg mypage.php?tab=tab2 then get that on the page

 $tab = $_GET['tab'];
    <ul class="tab-links">
    <li class="tab <?php if($tab=='tab1')echo "active"; ?>"><a href="#tab1"> tab1 </a></li>
    <li class="tab <?php if($tab=='tab2')echo "active"; ?>"><a href="#tab2"> tab2 </a></li>
    <li class="tab <?php if($tab=='tab3')echo "active"; ?>"><a href="#tab3"> tab2 </a></li>
    <li class="tab <?php if($tab=='tab4')echo "active"; ?>"><a href="#tab4"> tab2 </a></li>
</ul>
<div class="tab-content">
    <div id="tab1"  class="tab <?php if($tab=='tab1')echo "active"; ?>">

    </div>

    <div id="tab2" class="tab <?php if($tab=='tab2')echo "active"; ?>">

    </div>

    <div id="tab3"  class="tab <?php if($tab=='tab2')echo "active"; ?>">

    </div>

    <div id="tab4"  class="tab <?php if($tab=='tab4')echo "active"; ?>">

    </div>

Upvotes: 1

Related Questions