Solved

How do I get links not located within the tabs div to go to and open specific tabs?

Posted on 2016-09-14
5
75 Views
Last Modified: 2016-09-22
http://embroideredpatches.net/test/scouting/scout_custom_patches.html

I want the blue buttons to jump down to the tabs on the bottom of the page and also land on the matching tab. So, for example, if the blue "Woven Patch Pricelist" button is clicked, I want it to scroll down to the tabs and also open the "woven patches" tab. Right now if seems to be scrolling down but not activating the matching tab.

Does that makes sense?
0
Comment
Question by:underrugswept
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 57

Assisted Solution

by:Julian Hansen
Julian Hansen earned 500 total points
ID: 41798483
I believe this should do it
$('.btn-add-cart').click(function() {
  var target = 'a[href="' + $(this).attr('href') + '"]';
  $(target).tab('show');
});

Open in new window

0
 
LVL 1

Author Comment

by:underrugswept
ID: 41806571
That did work. Thanks. Sorry it took so long to respond; I got working on other things. Do you find that it lands about 100 pixels too low? Is that because of the navigation bar that stays on top of the page no matter what?
0
 
LVL 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41806740
The code above does not deal with the scrolling - that is happening because the target id is under the tab headings - the scroll be to place the id at the top of the screen - even if you take the menu away it will still scroll the tabs out of view.

To fix that you need your target points to be above the tabs.

What you could do is this
Change the
<div class="product-tab">

Open in new window

to
<div class="product-tab" id="product-tab">

Open in new window

Then your links change from
<a class="btn-add-cart" href="#100">100% Emb. Pricelist</a>

Open in new window

To
<a class="btn-add-cart" href="#product-tab" data-tab="#100">100% Emb. Pricelist</a>

Open in new window

Note all links now point to #product-tab and we have added a custom data attribute that now has the Tab target.
We change the jQuery to
$('.btn-add-cart').click(function() {
  var target = 'a[href="' + $(this).data('tab') + '"]';
  $(target).tab('show');
});

Open in new window

This gets us most of the way. What we are doing is pointing the links to the top of the Tab Menu rather than the individual tabs. This still puts the tabs under the menu.
We can get around that by changing the margin-top on the product-tab to padding and increasing it a bit
Line 4095 of styles.css
.product-tab {
  padding-top: 50px;
}

Open in new window

That should do it.
0
 
LVL 1

Author Comment

by:underrugswept
ID: 41810991
Perfect as always!
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41811171
Thanks and you are welcome.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remaiā€¦
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question