Solved

Jquery tabs click

Posted on 2011-09-17
8
238 Views
Last Modified: 2012-05-12
Hello.

Please tell me what is wrong here:

$("#featured > ul").bind("tabsselect", function(event, ui) {
  	selectedTab =$("#featured > ul").tabs().data("selected.tabs");
	alert (ui.index);
)}

Open in new window


ui.index is undefined. I need that for click event.

Please Help.
0
Comment
Question by:radugheorghies
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36553683
if ui is the element that is clicked, you can replace it with

alert($(this).index());
0
 

Author Comment

by:radugheorghies
ID: 36553720
Hello gurvinder372

alert($(this).index()) in my fuction is always -1 (for all tabs).
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36553725
okay, tell me one thing

$("#featured > ul").bind("tabsselect", function(event, ui) {
        //selectedTab =$("#featured > ul").tabs().data("selected.tabs");
      //alert (ui.index);
     alert($(this).html());
)}

when you select tab, does this alert the correct tab?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:radugheorghies
ID: 36553745
this is what I get on any tab:

            
 <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><div class="spatiu1"><a href="#fragment-1"><img src="images/gol.gif" alt="" height="100" width="138"></a></div></li>
	        <li class="ui-tabs-nav-item" id="nav-fragment-2"><div class="spatiu2"><a href="#fragment-2"><img src="images/gol.gif" alt="" height="100" width="138"></a></div></li>
	        <li class="ui-tabs-nav-item" id="nav-fragment-3"><div class="spatiu3"><a href="#fragment-3"><img src="images/gol.gif" alt="" height="100" width="138"></a></div></li>
	        <li class="ui-tabs-nav-item" id="nav-fragment-4"><div class="spatiu4"><a href="#fragment-4"><img src="images/gol.gif" alt="" height="100" width="138"></a></div></li>
            <li class="ui-tabs-nav-item" id="nav-fragment-5"><div class="spatiu5"><a href="#fragment-5"><img src="images/gol.gif" alt="" height="100" width="138"></a></div></li>

Open in new window


This is what alert($(this).html()) is doing.
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36553752
why don't you simply do

alert($(".ui-tabs-selected").index());

since by now you know which one is selected, because .ui-tabs-selected class is attached to it
0
 

Author Comment

by:radugheorghies
ID: 36553801
hmmm.

alert($(".ui-tabs-selected").index()); is always -1.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36553806
even if you select some other tab also?

In that case, whatever plugin you are using, is not assigning the class properly
0
 

Author Comment

by:radugheorghies
ID: 36553926
i did it in other way:

var mycheckedtab=setInterval("checktabs()",200);

function checktabs(){
	if ($("#nav-fragment-2").hasClass("ui-tabs-selected")){
		$("#fragmentelemele-1").show();
		$("#fragmentelemele-2").hide();
		$("#fragmentelemele-3").hide();
		$("#fragmentelemele-4").hide();
		$("#fragmentelemele-5").hide();	
	}
	
	if ($("#nav-fragment-3").hasClass("ui-tabs-selected")){
		$("#fragmentelemele-1").hide();
		$("#fragmentelemele-2").show();
		$("#fragmentelemele-3").hide();
		$("#fragmentelemele-4").hide();
		$("#fragmentelemele-5").hide();	
	}
	
	if ($("#nav-fragment-4").hasClass("ui-tabs-selected")){
		$("#fragmentelemele-1").hide();
		$("#fragmentelemele-2").hide();
		$("#fragmentelemele-3").show();
		$("#fragmentelemele-4").hide();
		$("#fragmentelemele-5").hide();	
	}
	
	if ($("#nav-fragment-5").hasClass("ui-tabs-selected")){
		$("#fragmentelemele-1").hide();
		$("#fragmentelemele-2").hide();
		$("#fragmentelemele-3").hide();
		$("#fragmentelemele-4").show();
		$("#fragmentelemele-5").hide();	
	}
	if ($("#nav-fragment-1").hasClass("ui-tabs-selected")){
		$("#fragmentelemele-1").hide();
		$("#fragmentelemele-2").hide();
		$("#fragmentelemele-3").hide();
		$("#fragmentelemele-4").hide();
		$("#fragmentelemele-5").show();	
	}
	}

Open in new window


Thanks for suggestion gurvinder372.

I think it is something wrong with jQuery UI.
I am using 1.3.2 version.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

820 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