0

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>

My form it's dynamic, and i need to remove one div after each data-tipo="TEXT". If I want to find the class "box-pai" i just find('.box-pai'), but how can I find the pseudo element data-tipo="TEXT" ?

Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • 1
    Did you search in google or stackoverflow before posting? See https://stackoverflow.com/questions/2487747/selecting-element-by-data-attribute – jasie Jan 07 '19 at 12:36
  • 2
    Side note: "pseudo-element" has [a specific meaning](https://www.w3.org/TR/selectors-3/#gen-content) in web programming, and there aren't any in your question. (A *pseudo-element* is the fake element created by providing text in a `::before` or `::after` rule in CSS.) – T.J. Crowder Jan 07 '19 at 12:38

1 Answers1

2

You can select by attribute, and then use .next("div") to find the next 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>
Reinstate Monica Cellio
  • 25,975
  • 6
  • 51
  • 67