我有一个链接,可以将一些数据发布到 Controller 。它工作正常并更新数据。但我想更改父 div 的 css 但它没有发生。我尝试了很多变化,但我一定做了一些愚蠢的事情。
代码如下
查看:
@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>
最佳答案
你尝试过吗:
$(this).parents('.added-property-excerpt').css("background", "red");
parent
与s。
它的作用是从一个父级到另一个父级,直到找到您想要的类。
关于jquery parent /最近的不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12878215/