我試圖在兩個元素上添加hidden
類。多元素的jQuery高級選擇器
$("#grid").closest(".ui-jqgrid").addClass("hidden");
$("#grid").closest(".ui-jqgrid").prev("h3").addClass("hidden");
對於下面的標記,
<div class="col-sm-12">
<h3>Heading 1</h3>
<div class="ui-jqgrid hidden" id="" dir="rtl" style="width: 1035px;">
<div class="jqgrid-overlay ui-overlay" id=""></div>
<div class="loading row" id="" style="display: none;"></div>
<div class="ui-jqgrid-view" role="grid" id="">
<div class="ui-jqgrid-titlebar ui-jqgrid-caption-rtl" style="display: none;">
<a role="link" class="ui-jqgrid-titlebar-close HeaderButton " title="" style="left: 0px;">
<span class="ui-jqgrid-headlink glyphicon glyphicon-circle-arrow-up"></span></a>
<span class="ui-jqgrid-title"></span>
</div>
<div class="ui-jqgrid-bdiv">
<div style="position: relative;">
<div></div>
<table id="grid" class="ui-jqgrid-btable">
</table>
</div>
</div>
</div>
</div>
</div>
我能做到這一點在一行中仍然沒有找到closest(".ui-jqgrid")
兩次?我不想添加更多的類來標記,我也不想在這裏使用JS變量。任何具有強大選擇器的人都可以提出解決方案嗎?
謝謝。有什麼方法可以使用addClass(「隱藏」)只有一次? –
不以這種方式,addClass每次都在differend元素上執行 – kapantzak
感謝您更新的ansers,實際上就像我上面提到的那樣,我不想爲標記添加更多的類。 –