Monday, 12 August 2013

If jQuery has Class do this action

If jQuery has Class do this action

I am trying to check whether or not a particular element has been clicked
but am having trouble doing so. Here is my 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">&nbsp;</label>
<span class="switch-right switch-small switch-danger">OFF</span>
</div>
</div>
Here is my 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 am guessing that my id "my_special_id" is not what is actually being
clicked?

No comments:

Post a Comment