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() {

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



<script src=""></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


source to share

1 answer

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

and inside it something like (pseudocode-ish)



So connecting

$(".prev").on("click", function() {


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.



All Articles