I have the following JavaScript where I have some lists:
var deleteLinks = $(".remove-button .remove-from-cart");
deleteLinks.on('click', function(ev){
ev.preventDefault();
console.log("registered: " + deleteLinks);
var currentHTML = $('.product');
var currentText = $('.product .product-details .name-header');
var newHTML ;
$.ajax({
url: this.href,
type: "GET",
dataType: "html",
success: function(data) {
newHTML = $(data).find('.product .product-details .name-header');
for(i = 0; i < newHTML.length; i++){
console.log("new: " + newHTML[i].innerText);
console.log("old: " + currentText[i].innerText);
}
}
});
});
The variable currentHTML
contains an array of divs which are a container. The currentText
contains an array of each container's name. The variable received in the AJAX response (newHTML
) contains an array of names. This array is updated after some user interaction. One or more entries of the currentText
variable may be missing and I want to find the indices of them so I can remove them from the container (currentHTML
).
Can someone help me to find the indices of the missing elements between currentText
and the retrieved data (newHTML
)?