Jquery - Is there a way to connect buttons?

Asked

Viewed 90 times

1

I am beginner in programming I am working with wordpress. On the site I’m helping I have a Slider Revolution with 4 balloons that will serve as buttons. And in the body of the site I have a Portfolio plugin with filters.

I wonder if you have a method for that:

  • I can make that when someone clicks on one of the balloons activate the "button" of the filter. (I don’t know the class that activates the function).

    • A method to find the function if the first item is missed.

Example of the case:

<div id="1">
<a id="btn1" href="#">Primeiro "botão" sem Função<a>
</div>

<div id="2">
<a id="btn2" href="#">segundo "botão" com Função<a>
</div>

I would like when I click on btn1 to activate btn2.

Filter - http://www.mperrenoud.com.br/home-4 Silde - http://www.mperrenoud.com.br/

The two will be on the same page.

2 answers

1


See if that helps you:

HTML:

  <button class="btn btn-primary" id="first">1</button>
  <button class="btn btn-primary" id="second">2</button>

JS:

$('#first').click(function (e){
  e.preventDefault();
  $('#second').click(); 
});

$('#second').click(function (e){
  e.preventDefault();
  console.log('Teste')
});

http://jsbin.com/yebirozuxe/2/edit?html,js,console,output

  • You’re genius just like that.

1

I’m not sure I understand your question, but from what I’ve seen you want to fire a function from one button when clicked on another, correct?

I’d use the jQuery trigger - http://api.jquery.com/trigger/

// quando clica no btn 1
$("#btn1").on("click", function(){
  // Dispara btn2
  $("#btn2").trigger("click");
});

Quando clica em btn 2
$("#btn2").on("click", function(){
  // Faz algo
});
  • Thank you very much !! helped a lot.

Browser other questions tagged

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