Trigger event by clicking on a "tab"

Asked

Viewed 477 times

0

I have a series of "tab" that are generated according to the parameters

code:

if($i==0 || $i==2 || $i==16 || $i==26  )
                    {
                        ?>

                        <div class="panel with-nav-tabs panel-primary">
                        <div class="panel-heading"><?if($i==0) {Echo"Preparo da área";
                                                    }elseif($i==2){
                                                    Echo"1° Ciclo de plantio";
                                                    }elseif($i==16){
                                                      Echo"2° Ciclo de plantio";
                                                     }else {Echo"3° Ciclo de plantio";}?></div>
                        <div class="panel-body">    
                        <div class="tl-heading">  <!--/#começolinhadotempo-->
                        <?php
                        $tst=0;
                        ?>
                        <div class="tabbable" id="<?=$tst?>">
                        <ul class="nav nav-tabs">
                        <?php $tst=$tst+1;?>

                        <?

To trigger the event I want I use the following code:

$('#0 li:eq(0)').click(function (e) {
    if($('#meses_rel').val()=="14") {
        $('.progress-bar').css('width', '8%').attr('aria-valuenow', 8);  
        $('.progress-bar').text('8%');
        $("#etapa").html('Etapa-Preparo da área');  
    } else {
        $('.progress-bar').css('width', '4%').attr('aria-valuenow', 4);
        $('.progress-bar').text('4%');
        $("#etapa").html('Etapa-Preparo da área'); 
    }

    console.log('entrou');
});

$('#1 li:eq(0)').click(function (e) {
    if($('#meses_rel').val()=="14") {
        $('.progress-bar').css('width', '50%').attr('aria-valuenow', 50);  
        $('.progress-bar').text('50%');
        $("#etapa").html('Etapa-Preparo da área');  
    } else {
        $('.progress-bar').css('width', '4%').attr('aria-valuenow', 4);
        $('.progress-bar').text('4%');
        $("#etapa").html('Etapa-Preparo da área'); 
    }

    console.log('entrou');
});

$('#0 li:eq(1)').click(function (e) {
    if($('#meses_rel').val()=="14") {
        $('.progress-bar').css('width', '16%').attr('aria-valuenow', 16);  
        $('.progress-bar').text('16%');   
        $("#etapa").html('Etapa-Preparo da área');
    } else {
        $('.progress-bar').css('width', '8%').attr('aria-valuenow', 8);
        $('.progress-bar').text('8%');
        $("#etapa").html('Etapa-Preparo da área'); 
    }
});

For Tab with id=0 works normally,but for other tabs that increment 1 in the value of "tst", for example id=1,doesn’t work. Does anyone know what the mistake is?

  • You say não funciona which means it doesn’t call the event?

  • @Dontvotemedown yes, does not call the event

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.