How do I click a link to activate a JS function on another page? [duplicate]

1

I want to click on the link on the first page, it goes to the second page and does the JS function, which is to show only what belongs to the sport of the link

I want to click the link on the first page and go to the second one and activate js in the second one by the click of the first page

I thought of something with anchor but I did not find a solution

this is page 1

<div>
  <ul id="Menu1">
     <li class="Esporte"><a href="Pagina2.html"><p>Futebol</p></a></li>
     <li class="Esporte"><a href="Pagina2.html"><p>Basquete</p></a></li>
     <li class="Esporte"><a href="Pagina2.html"><p>Outros</p></a></li>
  </ul>
</div>

Page 2

<div class='Modalidade'>    <p class='Esporte1'>    Futebol </p></div>
<div class='Modalidade'>    <p class='Esporte1'>    Basquete    </p></div>
<div class='Modalidade'>    <p class='Esporte1'>    Outros  </p></div>

JS

 $('#Menu1 .Esporte').click(function(){
    var Esportes = $(this).text();
    $('.Modalidade').hide();
    $('.Modalidade .Esporte1:contains(' + Esportes + ')').parent().show();
 });
    
asked by anonymous 30.01.2016 / 13:54

1 answer

0

@Ney, by JS I see that you are hiding one div and showing another. Is this the intention or is it to call another html page? Does this information you want to show that depends on the sport he clicks on the list will come from the correct bank? Before parent().show() make the request:

$.ajax({
  type: 'post', //Tipo de envio, GET, POST....
  data: 'esporte=Esporte', // envio da variavel Esporte com o texto (acho mais interessante você passar um valor que seria uma chave primaria mais vai depender do seu banco de dados
  url:'dados.php', // Url do arquivo que vai chamar
  success: function(retorno){
      $('.Modalidade .Esporte1:contains(' + Esportes + ')').parent().show();
  }
   })

I've reviewed your code what you want is to switch to page2.html and just show what is in the sport div that the person clicked on. You can still do it the way I found it here in StackOverflow. Stack Link on the same subject.

    
30.01.2016 / 14:04