How do I click on a link and activate a JS function on another page?

Asked

Viewed 434 times

1

want that when clicking on the link of the first page, it goes to the second page and makes the function JS, that is to show only what belongs to the sport of the link

ie I want to click on the link of the first page and go to the second and be activated the js on the second by the click of the first page

I thought of something with anchor but I found no 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();
 });
  • @Ney you’ve done this question and you solve the above problem using itself!

1 answer

0

@Ney, by the JS I see that you are hiding one div and showing another. The intention is this or is to call another html page? This information you want to show that depends on the sport that it click on the list will come from the correct bank? Before the 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 reviewed your code what you want is to switch to the pagina2.html and show only what is in the sport div that person clicked. You can still do it the way I found it here at Stackoverflow. Stack link on the same subject.

  • what I want is, clicked on page 1 football link, opens page 2 and shows only football

  • I believe these three existing ways to do what you want. I edited the comment I made and added another Stack page that has 2 ways to do what you want.

Browser other questions tagged

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