Solved

Jquery tabs click

Posted on 2011-09-17
8
231 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now