I'm trying to write JQuery to remove all divisions with class item ui-draggable...
based on the value of the highlighted element. For instance check if the value is less than 100, and if true, remove the division. I have no idea how to do this, however. The structure of all the divisions are the same. The relevant number will always be contained in the 6th sub-element of the division to be removed.
so in pseudo-code I want to write this:
$(document).ready(function(){
for each division of class .item ui-draggable... {
if (value of relevant number < 100) {
.remove(division);
}
}
});
First select the elements you want to assess, and then, if those elements meet the criteria, move up to the relevant element with closest()
or parents()
, and remove those:
$('em.socialMetaCount').filter(function(){
return parseInt(this.textContent.trim(), 10) < 100;
}).closest('.item.ui-draggable').remove();
References:
Try this:
$(document).ready(function(){
$('.item.ui-draggable').each(function(){
var val = parseInt($(this).find('.socialMetaCount').text(),10);
if (val < 100) {
$(this).remove();
}
})
});
So in code you wanted to write is
$(document).ready(function(){
$(".item ui-draggable").each(function(){
if (anyNumber< 100 && somethingTrue) {
$(this).remove();
}
}
});
I think that what you are looking for is something like this:
$(document).ready(function() {
$(".ui-draggable").each(function() {
if (parseInt($(this).find('.socialMetaCount').text()) < 100) {
$(this).remove();
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.