HOW TO JQUERY TOGGLE SWITCH GIVES NULL ON DOCUMENT READY

john rob

Total Post:108

Points:756
Posted by  john rob
 881  View(s)
Ratings:
Rate this:

Hi Im using jquery ui toggleswitch toggleswitch.js

how can i get on /off value on document ready

i'm using this code on document ready

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

it gives null but when i use firebug console and run it gives value of on/off by running this code below.

$('.ui-state-active').html()

there is not much documentation of this widget can anybody help?

 

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to Jquery toggle switch gives null on document ready

    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>

     

      Modified On Apr-09-2018 12:46:18 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!