• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

Problem in JQuery tabs

Hi.

I'm working on this page:

http://doslekqwod23ay.opencosmetic.com/cosmetic-clinics/the-cosmetic-clinic

I'm facing a problem with jQuery tabs: if you click on reviews tab, after this, when you click on other tabs they became all marked.

The code of this page is huge, but I make a comment on the javascript code (jQuery code) that seems to break tabs. Please look for this comment: // This code seems to break tabs

This little javascript is supposed to make links to point to a tab. What am I doing wrong ?

Thank you.
0
gplana
Asked:
gplana
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
macarrillo1Commented:
The problem is not the third tab (review).  The problem can also be recreated with the second tab. What I noticed is if I click the third tab; it works. Then click the second tab; there is a problem.  Then click the third tab and then the first it starts working again.

The problem is that your code is spread out.  Perhaps you could create a function that takes the link and the tab as parameters.  Then set them when the user clicks a tab.
0
 
gplanaAuthor Commented:
Thanks for your answer, but I think I don't understand. What do you mean "spread out" ?

What do you mean about create a function ? Do you mean a jQuery function ? Can you give me an example ?
0
 
mcnuteCommented:
Maybe this breaks your page:

TypeError: $("#slider ul").bxSlider is not a function
http://doslekqwod23ay.opencosmetic.com/wp-content/themes/absoluteme/js/scripts.js
Line 7
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Steve KrileCommented:
It looks like you have the code in on your page THREE times.
		<script>
			// This code seems to break tabs
			var $tabsft = $('#clnc-tabs').tabs(); // first tab selected
			$('#clinic_treatments_link').click(function() { // bind click event to link
				$tabsft.tabs('select', 2); // switch to second tab
				return false;
			});
		</script>

Open in new window



Also you have three anchor tags with the SAME ID.
id="clinic_treatments_link"


Each anchor tag needs its own ID, and you should only need the code to trigger click activity once.

Here is a simple working example showing how all this should be put together.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="Evan Cutler" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/themes/smoothness/jquery-ui.css" />
<title>Untitled 2</title>
    
    <style type="text/css">
        body {font-family:Arial;}
        
    </style>
    <script type="text/javascript">
		$(function() {
			$( "#tabs" ).tabs();
		});
        
    </script>
    
</head>

<body>
<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Nunc tincidunt</a></li>
		<li><a href="#tabs-2">Proin dolor</a></li>
		<li><a href="#tabs-3">Aenean lacinia</a></li>
	</ul>
	<div id="tabs-1">
		<p>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.</p>
	</div>
	<div id="tabs-2">
		<p>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.</p>
	</div>
	<div id="tabs-3">
		<p>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.</p>
		<p>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.</p>
	</div>
</div>
</body>
</html>

Open in new window

0
 
macarrillo1Commented:
Sorry for the late response; work got very busy.

skrile, hit the nail on the head. Your code is repeated through out your page.  My thought earlier was for you use a variable for the links and the tabs if you were going to be calling your code from different locations(events) on your page.  However, you don't need to do that, you can just use a single event; as skrile described above.
0
 
gplanaAuthor Commented:
The problem is that I want two boxes below every tab, and these boxes has links to the other two tabs. This is why I put these code, and this is why it is repeated.

Should I maybe change id by class and then reference it by using a dot instead of # ?
0
 
Steve KrileCommented:
Gotcha.  You can use the .tabs() select method in this modified code.  You will only need this code ONCE.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="Evan Cutler" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.23/themes/smoothness/jquery-ui.css" />
<title>Untitled 2</title>
    
    <style type="text/css">
        body {font-family:Arial;}
        
    </style>
    <script type="text/javascript">
		$(function() {
			$( "#tabs" ).tabs();
			
			//wire up a click event for all DOM elements that you tag with .tabselector
			//these will be <a> tags.  We will use this code to strip the HREF out of the Anchor tag and
			//find the target tab you need to be selected
			$(".tabselector").click(function(e){
				//stop the normal link behavior
				e.preventDefault();
				
				//get the tab reference for this link
				var tabRef = $(this).attr("href").split("-")[1];
				
				//set the proper tab to be active
				$( "#tabs" ).tabs('select', tabRef);
			});
		});
        
    </script>
    
</head>

<body>
<div id="tabs">
	<ul>
		<li><a href="#tabs-1">Nunc tincidunt</a></li>
		<li><a href="#tabs-2">Proin dolor</a></li>
		<li><a href="#tabs-3">Aenean lacinia</a></li>
	</ul>
	<div id="tabs-1">
		<p>This is a link to the <a href="#tabs-2" class="tabselector">Second tab</a>.</p>
		<p>This is a link to the <a href="#tabs-3" class="tabselector">Third tab</a>.</p>
		<p>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.</p>
	</div>
	<div id="tabs-2">
		<p>This is a link to the <a href="#tabs-1" class="tabselector">First tab</a>.</p>
		<p>This is a link to the <a href="#tabs-3" class="tabselector">Third tab</a>.</p>
	<p>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.</p>
	</div>
	<div id="tabs-3">
		<p>This is a link to the <a href="#tabs-1" class="tabselector">First tab</a>.</p>
		<p>This is a link to the <a href="#tabs-2" class="tabselector">Second tab</a>.</p>
	<p>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.</p>
		<p>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.</p>
	</div>
</div>
</body>
</html>

Open in new window

0
 
gplanaAuthor Commented:
Thanks a lot. All you are helping me a lot.

I think now I'm closer to the solution. Now tabs are working fine, but links doesn't work fine, despite I copyied and adapted your code above.

Also, I think tabRef parameter should be 0 based instead of beign 1 based, so I think last line of javascript code should be:

$( "#tabs" ).tabs('select', tabRef-1);

However I tryied too and links still doesn't work.

Can you help me in finding my error ?
0
 
Steve KrileCommented:
I'm having trouble finding your jquery code.  What file is it in?  Also, I can't seem to find the links you are trying to use to select tabs.  Can you point me in the right direction - this page is quite loaded with content  :)
0
 
gplanaAuthor Commented:
I missed the name of the class. It's working fine now.

Thanks for you help. I wouldn't solve this issue without your help. It's very good to know there are always people wanting to help.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now