我有一些json响应,我需要根据主题从json响应中删除一些匹配的元素。
检查jQuery代码从json响应中删除HTML元素的位置。
我尝试了remove()方法,但是在这里没有用。 HTML Strcture看起来像这样,一旦匹配主题后,我想基于主题删除匹配的元素,然后从响应变量中删除匹配的元素:
<div class="mailleft_cover" data-abc="New Whatsapp Chat Message From: 91956953****@c.us">
<div class="checkbox">
<label>
<input type="checkbox" class="mailUid" value="384">
</label>
<span class="glyphicon glyphicon-star-empty single_move_starred"></span>
</div>
<a href="#" data-uid="384" data-mailbox="INBOX" class="list-group-item wml_get_single_mail active">
<span class="hide"></span>
<span class="email"><img alt="icon" class="whatsppp-icon" src="http://54.161.237.21.xip.io/wp-content/plugins/box_26_12_18/images/whatsppp.png"><span class="personcontact"> 91956953****</span></span>
<br>
<span class="last-msg c2">again next message</span>
<span class="subject hide"><em>New Whatsapp Chat Message From: 91956953****@c.us</em></span>
<span class="badge">Feb 19</span>
</a>
<span class="show_drop"><i class="glyphicon glyphicon-chevron-right"></i></span>
</div>
<div class="mailleft_cover">
<div class="checkbox">
<label>
<input type="checkbox" class="mailUid" value="378">
</label>
<span class="glyphicon glyphicon-star-empty single_move_starred"></span>
</div>
<a href="#" data-uid="378" data-mailbox="INBOX" class="list-group-item wml_get_single_mail">
<span class="hide"></span>
<span class="email">developer.odz@gmail.com</span>
<span class="message-icon"><span class="glyphicon glyphicon-envelope"></span></span><br>
<span class="last-msg c2"><em>Jinny the jin</em></span>
<span class="subject hide"><em>Jinny the jin</em></span>
<span class="badge">Feb 19</span>
</a>
</div>
jQuery代码从json响应中获取数据,然后过滤数据并在此之后检查与dom元素匹配的主题,我想从response.htmldata变量中删除匹配的元素:
jQuery(response.htmldata).filter('.mailleft_cover').each(function(i) {
var subject = jQuery(this).attr('data-abc');
var current_div = jQuery(this).html();
jQuery(document).find('.mailleft_cover').each(function(i) {
var domElem = $(this).find('a > span.subject em')[0];
var domElem = jQuery(domElem).text();
var activeElem = false;
ifnew = false;
if (domElem == subject) {
var this_ = jQuery(this);
if (jQuery(this_[0]).find('a').hasClass('active')) {
console.log('Logging this elem: ', this_[0]);
activeElem = true;
}
var test = jQuery(this).html(current_div);
if (activeElem) {
jQuery(test[0]).find('a').trigger('click');
}
//Now remove current div from response.htmldata
return false;
} else {
ifnew = true;
console.log('subject not matched');
//var test = jQuery(this).html(current_div);
}
});
});