Tuesday, 20 August 2013

jquery switch checked button to on and off depending on the result

jquery switch checked button to on and off depending on the result

i have a checked button on my view page .... i want to switch the botton
from on and off depending on the result .. here is the button on my view
page

my code
<input type="checkbox" name="newsletter" id="newsletter" value="1"
class="switch replacement" checked data-text-on="YES"
data-text-off="NO">
$(document).ready(function () {
$.get('userinfo/newsletter', function (datas) {
if (datas==1){
$('#newsletter')[this.checked ? 'addClass' : 'removeClass']('switch
replacement replacement');
}
});
});
but is not working write now ... if the button is ON i see this class in
firebug which is dynmically created
<span class = "switch replacement checked replacement">
and if the button is off then the class is
"switch replacement replacement"

No comments:

Post a Comment