---
title: "Jquery Toggle If statement"  
description: "Jquery Toggle If statement"  
author: "Anonymous User"  
published: 2014-11-23  
updated: 2014-11-24  
canonical: https://www.mindstick.com/forum/12682/jquery-toggle-if-statement  
category: "jquery"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Jquery Toggle If statement

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to run a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) when the state of the [toggle](https://www.mindstick.com/forum/156565/show-hide-and-toggle-effects-in-javascript) is only "open". [Right now](https://answers.mindstick.com/qa/36863/what-would-happen-if-gravity-became-5-percent-stronger-right-now) the function [runs](https://answers.mindstick.com/qa/48615/when-was-the-runs-in-ruins-written) either way. I'm not entirely sure how to make it so that it only runs when the toggle is opened. I found the toggle [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) somewhere and used it, it works great.

```
$( "#SB2p" ).click(function() {        $( "#SB2").toggle('slow',function(){            var $link =$("#SB2p");            $(this).is(":visible")
? $link.text("<<<") : $link.text(">>>");        });        accumulative();    });
```

Any help would be great.

## Replies

### Reply by Anonymous User

You already have a working example. The ternary operator uses $(this).is(':visible'), so use that:

```
   $( "#SB2p").click(function() {        $( "#SB2").toggle('slow',function(){            var $link =$("#SB2p");            if ($(this).is(":visible"))
           {              $link.text("<<<");             
           accumulative();            } else {              $link.text(">>>");            }        });           });
```


---

Original Source: https://www.mindstick.com/forum/12682/jquery-toggle-if-statement

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
