Toggle jQuery.remove()
Instead of .show()'ing and .hide()'ing (or .toggle()'ing for that matter), is there any way to "toggle" a .remove() function?
I realize .remove() literally removes elements from the DOM, so it sounds difficult to magically replace the removed elements once they're gone, but is there a way of faking it?
Note: They must be removed from the DOM so that they are ignored by screen reader开发者_如何学JAVAs (AFAIK screen readers do not respect .show() and .hide()).
Thanks.
--- EDIT ---
OK, so .detach() might work for me. If my markup is:
<a href="#">Toggle images</a>
<p><span>Some text here</span><img src='image1.png'/><img src='image2.png'/></p>
<p><span>Some more text</span><img src='image2.png'/></p>
<p><span>Even more text</span><img src='image5.png'/><img src='image1.png'/>
<img src='image5.png'/></p>
And by clicking the anchor it would remove all images, and clicking again would restore. Using .detach() how would it work?
--- EDIT #2 ---
As thenduks pointed out, screen readers in fact do respect display: none;
which changes my question a bit. I ended up with a simple toggle code. Thanks!
You could try using jQuery 1.4's recent addition: detach
to remove them and then re-add them later.
You can save the DOM element(s) to a variable to be added back again later.
Check example here.
精彩评论