How in jQuery I can get the value of my element (i.e.: 2).
I try with $(this).("label").attr('for')
, but it does not work.
Thanks.
My HTML is:
<div class="checkbox col-sms-6 col-sm-6 moods">
<label for="2">
<input type="checkbox" id="2">2
</label>
</div>
My js is:
$("form").on("click", "div.moods", function(event){
var moodsId = $(this).("label").attr('for');
var moodsBtn = $('#moods');
var moodsBtnValue = $('#moods').val();
if(moodsBtnValue.toString().indexOf(moodsId) == -1) { moodsBtn.val(moodsBtnValue + moodsId + ","); }
else { moodsBtn.val(moodsBtnValue.replace(moodsId + ',','')); }
});