-3

Suppose to have a tab with 3 choices ("home","dog",house"). My purpose is to get the current selected element Anyone can help me?
I do this:

var r=$('#tab_sezioni ul li');

But in this way I take all tag

  • while I need to get the index of curentent select element of tab.
  • user6045391
    • 51
    • 1
    • 7

    1 Answers1

    0

    You could try using a class so you can tell which tab is selected. For example when you click on a tab add class selected.

         $('#tab_sezioni ul li').click(function(){
         $('#tab_sezioni ul li').removeClass('selected');
         $(this).addClass('selected');
         });    
    

    And then get only selected element

         var r=$('#tab_sezioni ul li.selected');
    

    Or if you want just the index

        var index=$('#tab_sezioni ul li').index($('#tab_sezioni ul li.selected'));
    
    George Pant
    • 2,079
    • 1
    • 9
    • 14