Ho un collegamento che registra alcuni dati su un controller. Funziona bene e aggiorna i dati. Ma voglio cambiare il css del genitore div ma non sta succedendo. Ho provato molte varianti ma devo fare qualcosa di stupido.jquery genitori/più vicini non funzionanti
Il codice è sotto
Vista:
@foreach (var item in Model)
{
<div class="added-property-excerpt">
...
<div class="added-property-links">
...
@if (!item.IsPropertyDisabled) {
@Html.ActionLink("Take off the Market" , "Disable", "Property", new { id = item.PropertyId }, new { id ="disable-link" })
}
else {
@Html.ActionLink("Bring on the Market" , "Enable", "Property", new { id = item.PropertyId }, new { id ="enable-link" })
}
</div>
</div>
}
JQuery
<script>
$(function() {
$('a#disable-link').click(function (e) {
$('.added-property-links').text('loading...');
$.ajax({
url: this.href,
dataType: "text json",
type: "POST",
data: {},
success: function (data, textStatus) { }
});
$(this).closest('.added-property-excerpt').css("background", "red");
// $(this).parent('.added-property-excerpt').css("background", "red");
e.preventDefault();
});
});
</script>
Potresti pubblicare un campione dell'HTML esportato? –
Hai legato i genitori() anziché il genitore() –
Stai generando un markup non valido. Gli ID devono essere unici. – undefined