Reputation: 1799
Could one kindly advise me why my javascript code is not working
i am using the gem simple_form, what i am trying to do is:
i am using javascript / toggle
new.html.erb
<div class="checkbox custom">
<%= f.input :remember_me, input_html: { class: 'css-checkbox' }, label_html: { class: 'css-label-notick' }, as: :boolean if devise_mapping.rememberable? %>
</div>
javascript file
$(document).ready(function() {
$('.css-label-notick').on('click', function (e) {
$('.css-label-notick').toggleClass(".css-label-tick");
});
});
i have displayed the details of the input within the image highlighted in red
css file
.css-label-notick {
background: url("img-checkbox-notick.png") no-repeat;
height: 65px;
}
.css-label-tick {
background: url("img-checkbox-tick.png") no-repeat;
height: 65px;
}
any advise would be much appreciated - many thanks
Upvotes: 1
Views: 74
Reputation: 8868
While using toggleClass method, you don't need to put period(.) in front of the classname.
$(document).ready(function () {
$('.css-label-notick').on('click', function (e) {
$(this).toggleClass("css-label-tick");
});
});
Working example : http://jsfiddle.net/xno5hb34/3/
Upvotes: 2