Have a set of checkboxes as such:
<div class="checkbox checkbox-inline">
<label id="test">
<input type="checkbox" class="icheck" checked value="<?=$skill->name; ?>"> <?=$skill->name; ?>
</label>
</div>
<div class="checkbox checkbox-inline">
<label id="test">
<input type="checkbox" class="icheck" checked value="<?=$skill->name; ?>"> <?=$skill->name; ?>
</label>
</div>
And i have the following JS
$('#test').on('click', null, function(){
alert("Clicked");
$(this).remove();
});
What i am trying is to remove individual checkboxes (with its label) when ever the user click on the label.
I would like to have something like this:
<div class="checkbox checkbox-inline">
<label id="test" onClick="removeMe()">
<input type="checkbox" class="icheck" checked value="<?=$skill->name; ?>"> <?=$skill->name; ?>
</label>
</div>
And on my javascript:
function removeMe(){
// Do some AJAX GET/POST
$.ajax....
// and finally
$(this).remove() // i am not sure how to do this....
}
Can anyone point me to the right direction? Thanks
EDIT:
So this is the solution that i use:
function removeMe(object, skillId, personId){
$.ajax({
type: 'POST',
url: SOME_URL_GOES_HERE,
dataType: 'json',
data: { skill_id: skillId, person_id: personId },
success: function(data, textStatus, jqXHR){
noty({
text: data.message,
layout: 'topRight',
type: data.response
});
$(object).remove();
},
error: function(data){
console.log(data);
noty({
layout: 'topRight',
text: 'Failed to delete record, please try again.',
type: 'error'
});
}
});
}
And as suggested, i use .class instead of id for my .
remove
in thecomplete
orsuccess
method of the$.ajax
call. See: api.jquery.com/jQuery.ajax