javascript - If jQuery has Class do this action -
i trying check whether or not particular element has been clicked having trouble doing so. here html:
<div id="my_special_id" class="switch switch-small has-switch" data-on="success" data-off="danger"> <div class="switch-on switch-animate"><input type="checkbox" checked="" class="toggle"> <span class="switch-left switch-small switch-success">on</span> <label class="switch-small"> </label> <span class="switch-right switch-small switch-danger">off</span> </div> </div>
here jquery:
<script type="text/javascript"> $(document).ready(function() { $('#my_special_id').click(function() { if ($('#my_special_id div:first-child').hasclass('switch-on')) { window.alert('on!'); } }); }); </script>
i guessing id "my_special_id" not being clicked?
since looking alert when checkbox clicked
$(document).ready(function() { $('#my_special_id input.toggle').click(function() { if ($('#my_special_id div:first-child').hasclass('switch-on')) { window.alert('on!'); } }); });
demo: fiddle
Comments
Post a Comment