所以我有这个jquery,我需要让它工作。但通过所有的父母()和孩子(),我无法到达我想要的地方。
我的目标是当我点击按钮时,班级图标交叉,切换到icon-tick。
(在下面的代码片段中,我举了一个例子来解释一下。在这种情况下我想改变矩形的颜色)
$(function() {
$(".addOpt").click(function(e) {
$(this).text(function(i, text) {
return text === "Add" ? "Remove" : "Add";
});
$(this).toggleClass("btn-primary btn-remove");
//the problem is the following line:
$(this).closest(".quoteCompare").children(".quoteCompareInside").p.toggleClass("icon-tick icon-cross");
e.preventDefault();
});
})

.icon-cross {
width: 50px;
height: 10px;
background-color: green;
}
.icon-tick {
width: 50px;
height: 10px;
background-color: red;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row ">
<div class="medium-6 xsmall-12 small-12 column quoteCompare ">
<div class="quoteCompareInside quoteStandard sameHeight2">
<p class="icon-cross"></p>
<p class="title noMarginBottom">10€</p>
</div>
</div>
<div class="medium-6 xsmall-12 small-12 column quoteCompare ">
<div class="quoteCompareInside quoteStandard sameHeight2">
<div class="form-row valign">
<button type="button" class="btn btn-primary buttonOpt addOpt">Add</button>
</div>
</div>
</div>
</div>
&#13;