Tanabe Saori
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>
How can I accomplish that?
ASKER
I'll have to get back to this; I have to teach a class now.
Thanks.
Thanks.
you can use this, to select hidden div inside #sortable59
$("#sortable59 div").filter(":hidden").remove();
I suggest
Ah, posted almost on top of Hain's but the syntax I use is easer to read in my opinion
$("#sortable59 div:hidden").remove()
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/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
or, if we plan to attach/use later again
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();
or, if we plan to attach/use later again
var hiddenDivs = $("#sortable59 div").filter(":hidden").detach();
Or just do
$("#sortable59 div:hidden").remove()
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 :)
ASKER
I'm sorry I made trouble.
...
On to the next trouble!
...
On to the next trouble!
No trouble at all :)
Open in new window