Check if a button is clicked in a jquery function

I am trying to figure out a way to check if a function is checked if a button is pressed. If this button is pressed to display anything. It's a little tricky. So I have a previous and next button, but depending on what is currently displayed, the previous and next functionality will change. Everything shows up or hides, so I can't use back.history or forward.history

Any way to check if a button is clicked from another function?

$(document).ready(function() {
$("#tear2").hide();
 $("#tear3").hide();
  $("#tear4").hide();

function pageCheck(){
if ($("#tear1").is(':visible')){
  
 if ($("#Prev").is(':clicked')){
    $("#tear1").show();
    }
    else if($("Next").is(':clicked')){
     $("#tear2").show();
      $("#tear1").hide();
    }
     
if ($("#tear2").is(':visible')){

  if($("#Prev").is(':clicked')){
      $("#tear2").show();
    
      alert("previous");
      
  }
      
  }
}
     

 }
   
});
    
      

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="tear1">This is me</div>
<div id="tear2">This is me</div>
<div id="tear3">This is me</div>
<div id="tear4">This is me</div>

<button id="Prev">prev</button>&nbsp;<button id="next">next</button>
      

Run codeHide result


+3


source to share


1 answer


You want an event handler $(".prev").on("click", function() {})

and inside it something like (pseudocode-ish)

$(".mytears>.active").removeClass("active").prev().addClass("active");

      

So connecting



$(".prev").on("click", function() {
    $(".mytears>.active").removeClass("active").prev().addClass("active");
});

      

It's not all the logic (the class active

needs to be defined, you don't have a container mytears

, and it doesn't loop to the beginning), but you get an idea of ​​how to do it.

0


source







All Articles