---
title: "How to Jquery toggle switch gives null on document ready"  
description: "How to Jquery toggle switch gives null on document ready"  
author: "Anonymous User"  
published: 2015-02-01  
updated: 2015-02-01  
canonical: https://www.mindstick.com/forum/12925/how-to-jquery-toggle-switch-gives-null-on-document-ready  
category: "javascript"  
tags: ["jquery", "jquery ui"]  
reading_time: 1 minute  

---

# How to Jquery toggle switch gives null on document ready

Hi Im using [jquery ui](https://www.mindstick.com/forum/34034/how-to-use-jquery-ui-modal-dialog) toggleswitch toggleswitch.js

how can i get on /off [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) on [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool) ready

i'm using this [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) on document ready

```
   $(document).ready(function () {     alert($('.ui-state-active').html());   }
```

it gives [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp) but when i use firebug [console](https://www.mindstick.com/blog/210/the-console-class) and run it gives value of on/off by running this code below.

$('.ui-state-[active](https://answers.mindstick.com/qa/97113/why-does-an-active-ftp-not-work-with-network-firewalls)').html()

there is not much [documentation](https://answers.mindstick.com/qa/30462/what-is-documentation) of this widget can anybody help?

## Replies

### Reply by Pravesh Singh

i think you run your code before plugin did it's job (also started at ready), first check if .ui-state-active esxist, if not run timeout and try again

```
function checkState() {  if ($('.ui-state-active').lenght) {    alert($('.ui-state-active').html());  } else {    setTimeout(function() {      checkState()    }, 500);   }} $(document).ready(function() {       checkState();    }<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
```


---

Original Source: https://www.mindstick.com/forum/12925/how-to-jquery-toggle-switch-gives-null-on-document-ready

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
