Avatar of Eduardo Fuerte
Eduardo Fuerte
Flag for Brazil

asked on 

How to use the same jquery code in two diferents parts of the same page?

Hi Experts

I need to use a the same code  in 02 parts of the same page with diferente contents:

My page use this tab near the top

         <ul class="tabs">
         <li><a href="#tab1" class="selected"> O que &eacute; ?</a></li>
         <li><a href="#tab2">PPAIS</a></li>
         <li><a href="#tab3">PNAE</a></li>
         </ul>

        <div class="tab" id="tab1" style="display: block;">
                <p style="text-align:justify"> Texto descritivo o que é ?</p>
        </div>
        <div class="tab" id="tab2">
        <p>Texto descritivo do PPAIS</p>
        </div>
        <div class="tab" id="tab3">
        <p>Texto descritivo do PNAE</p>
        </div>


<script>
$(function() {
  $('ul.tabs li a').click(function(e) {
    e.preventDefault();
    if (!$(this).hasClass('selected')) {
      $('.selected').removeClass('selected');
      $(this).addClass('selected');
      $('.tab').hide();
      $($(this).attr('href')).show();
    }
  });
});
</script>

Open in new window


I need to use it again in the botton part of the page (another similar tab with other content)

What must be changed in the 2nd use of the tab?

Thanks in advance!
jQueryCSSPHPJavaScript

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon