Предположим Jquery .each
цикл:
function reverifyDiscounts() {
//everything we need to verify a discount is already on the page.
//we'll remove the "bad" discounts when we submit the page
console.info("Entering reverification");
//event discounts are always valid once they're on the page because it's for the event
$(".discountPromoItem").each(function() {
//skip events
if ($(this).attr("appliesto") == $("#hdnEventID").val()) {
return true;
}
//we just need to make sure that the checkbox that the appliesto attribute references is checked!
if (!$("checkbox[attribute$='" + $(this).attr("applitesto") + "']").is(":checked")) {
//we also need to remove the promo code from the list of promo codes entered into the hidden textboxes
$("#hdnAppliedPromoCode").val($("#hdnAppliedPromoCode").val().replace($(this).attr("code"), ""));
//the item that it applies to is no longer selected and the promo must be removed
$(this).remove(); //can't remove $(this) while inside the loop for whatever reason.
}
});
recalculate();
}
Почему $(this).remove()
неудачу или я делаю что-то не так?
Вы можете иметь только один элемент с заданным идентификатором в документе –
Позвольте мне изменить код, потому что я на самом деле делает это на классе ... держись ... – MetalPhoenix
Прошу воспроизвести вашу проблему в скрипке. –