html:
<div id="pai_pergunta_0" class="col s12 card-panel hoverable box-pai" data-id="0" data-tipo="TEXT">
</div>
<div id="pai_pergunta_1" class="col s12 card-panel hoverable box-pai" data-id="1" data-tipo="RADIO">
</div>
<div id="pai_pergunta_2" class="col s12 card-panel hoverable box-pai" data-id="1" data-tipo="CHECKBOX">
</div>
我的表单是动态的,我需要在每个data-tipo =“ TEXT”之后删除一个div。 如果我想找到类“ box-pai”,我只想找到('.box-pai'),但是如何找到伪元素 data-tipo =“ TEXT” ?
答案 0 :(得分:2)
您可以按属性选择,然后使用.next("div")
查找下一个div ...
$("[data-tipo=TEXT]").next("div").remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div id="pai_pergunta_0" class="col s12 card-panel hoverable box-pai" data-id="0" data-tipo="TEXT">
TEXT
</div>
<div id="pai_pergunta_1" class="col s12 card-panel hoverable box-pai" data-id="1" data-tipo="RADIO">
RADIO
</div>
<div id="pai_pergunta_2" class="col s12 card-panel hoverable box-pai" data-id="1" data-tipo="CHECKBOX">
CHECKBOX
</div>