[英]How to remove a div with particular id containing particular text?
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". 我希望如果我取消选中一个复选框,那么具有id =“ result”的div应该被删除,其中包含文本“ Apartment”。 Currently this logic is not working for me.
目前,这种逻辑不适用于我。
or 要么
$('#checkboxId').change(function(){
if(!$(this).is(':checked')) {
if($('#result').text().indexOf("mystring")>-1) {
$('#result').remove();
}
}
});
particular id containing particular text?
包含特定文字的特定ID ?
if( $('elementselector').attr('id').indexOf('Apartment')>-1) { ..... }
unless there is some new JQ method out there 除非那里有一些新的JQ方法
( note - elements must have an ID, or check has ID first etc .. ) (note-元素必须具有ID,或者检查首先具有ID等。)
Try this http://jsfiddle.net/Tushar490/bg82uw8s/ 试试这个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();
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.