Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
91 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 59

Assisted Solution

by:Julian Hansen
Julian Hansen earned 2000 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 59

Accepted Solution

by:
Julian Hansen earned 2000 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 59

Expert Comment

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

Featured Post

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

670 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