views:

79

answers:

3

Dear All, I have using the code for developing tabs

  $(document).ready(function() {
              $('#container-1').tabs(); 
  }
   ....
  <div  id="container-1">
        <ul>
            <li><a href="#fragment-1"><span>Home</span></a></li>
            <li><a href="#fragment-2"><span>Contact</span></a></li>

         </ul>
  </div>

  ...

  It works fine! need The Tab Click Event ,If it is Home Tab Click I have to alert();
  How to achieve this!.Please help me!
A: 

Tidy up the formatting of your post.

However if you want the tab click event you would do something like one of the following....

$("#tabid").click(function(e) {
     e.preventDefault();
     // do tab click logic
});

or

$(".tabclass").click(function(e) {
     e.preventDefault();
     // do tab click logic
});

Do a search for jquery cheat sheet to get yourself a very useful jquery cheat sheet.

adam
+2  A: 

Set id of Home tab span element

<li><a href="#fragment-1"><span id="home">Home</span></a></li>

and add somethere click handler to it

$("#home").click(function()
{
    alert("Home tab is selected!");
});
Alexander Prokofyev
+1  A: 

Personally, I'd handle it all in the tab configuration itself rather than adding click events to the elements which ultimately will be the clickable part of the tab. If you do it via the tab config, then all of your tab logic is centralized thus making things cleaner and you don't need to be familiar with the implementation details of the tabs:

  $(document).ready(function() {
      $('#container-1').tabs({
          selected : function(e, ui) {
            if (ui.index == 0) {
                alert('Home clicked!');
            }
          }        
      }); 
  });
   ....
  <div  id="container-1">
        <ul>
            <li><a href="#fragment-1"><span>Home</span></a></li>
            <li><a href="#fragment-2"><span>Contact</span></a></li>

         </ul>
  </div>
Manik
Yes , I tried with your solution Not working I have included all necessary latest jquery plugin.any samples i welcom
venkatachalam
I use this in my tabbed pages and I whipped up a test before I posted, that being said I noticed the ending ); was missing from the actual example given (my apologies: fixed). Give that a go and we'll take it from there.
Manik
Thanks for Your Response , I waiting to see your code..
venkatachalam