Reputation: 323
if (!$(this).is(":checked")) {
$.each(function(){
if ($('#result').has("Apartment")) {
$('#result').remove();
}
})
}
I want that if I uncheck a checkbox then the div having id="result" should be deleted which contains the text "Apartment". Currently this logic is not working for me.
Upvotes: 0
Views: 71
Reputation: 1287
Try this http://jsfiddle.net/Tushar490/bg82uw8s/
var IsCheck;
var txt = $("#result").text();
$("#chk").change(function () {
IsCheck = $("#chk").is(":checked");
if (!IsCheck) {
if (txt === 'Apartment') {
$("#result").remove();
}
}
});
Upvotes: 0
Reputation: 3090
Try this,
$('#checkboxId').change(function(){
if(!$(this).is(':checked')) {
$('#result:contains(Apartment)').remove();
}
});
Upvotes: 2
Reputation: 5226
particular id containing particular text?
if( $('elementselector').attr('id').indexOf('Apartment')>-1) { ..... }
unless there is some new JQ method out there
( note - elements must have an ID, or check has ID first etc .. )
Upvotes: 0
Reputation: 497
or
$('#checkboxId').change(function(){
if(!$(this).is(':checked')) {
if($('#result').text().indexOf("mystring")>-1) {
$('#result').remove();
}
}
});
Upvotes: 0