Link to home
Start Free TrialLog in
Avatar of Tanabe Saori
Tanabe SaoriFlag for Japan

asked on

empty divs that are set to display:none

I have a div that contains divs that are set to display:none, which I want to empty before I submit a form:
<div id="sortable59">
    <div class="sideways" id="alpha0" style="display: none;">a
      <input type="hidden" name="order[]" value="_a_">
      <input type="hidden" name="name[]" value="Alphabet">
      <input type="hidden" id="levels590 name=" levs[]'="" value="2">
    </div>

    <div class="sideways" id="alpha1" style="display: none;">c
      <input type="hidden" name="order[]" value="_c_">
      <input type="hidden" name="name[]" value="Case">
      <input type="hidden" id="levels591 name=" levs[]'="" value="1">
    </div> 

    <div class="numways" id="nums0" style="">m
      <input type="hidden" name="norder[]" value="_m_">
      <input type="hidden" name="nname[]" value="Math">
      <input type="hidden" id="nums590 name=" levs[]'="" value="2">
    </div>

    <div class="numways" id="nums1" style="">n
      <input type="hidden" name="norder[]" value="_n_">
      <input type="hidden" name="nname[]" value="Numbers">
      <input type="hidden" id="nums591 name=" levs[]'="" value="4">
    </div>

    <input type="hidden" name="grade" value="WA">
    <input type="hidden" name="sid" value="59">
</div>

Open in new window

How can I accomplish that?
Avatar of HainKurt
HainKurt
Flag of Canada image

you need to remove or detach using jQuery

$("#sortable59 .sideways").remove();
//var divSideways = $("#sortable59 .sideways").detach(); 

Open in new window

Avatar of Tanabe Saori

ASKER

I'll have to get back to this; I have to teach a class now.
Thanks.
you can use this, to select hidden div inside #sortable59

$("#sortable59 div").filter(":hidden").remove();

Open in new window

Avatar of Michel Plungjan
I suggest

$("#sortable59 div:hidden").remove()

Open in new window


Ah, posted almost on top of Hain's but the syntax I use is easer to read in my opinion
Ah, posted almost on top of Hain's but the syntax I use is easer to read in my opinion

jQuery says different :)
https://api.jquery.com/hidden-selector/

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jQuery says, to find hidden elements, do this:

first select the elements with regular css selection

$("#sortable59 div")

then apply the filter

$("#sortable59 div").filter(":hidden")

our issue was to remove/detach these, so final code should be

$("#sortable59 div").filter(":hidden").remove();

Open in new window


or, if we plan to attach/use later again

var hiddenDivs = $("#sortable59 div").filter(":hidden").detach();

Open in new window


Or just do
$("#sortable59 div:hidden").remove()

Open in new window

which obviously works and I do not see why it shouldn't
which obviously works and I do not see why it shouldn't

yes it works, just jQuery says it is not efficient, use simple select + filter...
for a couple of select who cares the performance :)
I'm sorry I made trouble.
...
On to the next trouble!
No trouble at all :)