Multi
Multi
Simply put: Removing/hiding elements
Topic Started: Thursday, 7. July 2011, 14:08 (391 Views)
Joe
Member Avatar
Hi.
Please refer to this topic if you're not sure about div `id`'s and `classes`.

Sometimes you'll want to remove something, whether that be an option in a dropmenu, an entire div, etc, and it's very easy to do so. jQuery has a very, very simple `.remove()` feature. [bbc_code]$('div#omgdivid').remove();[/bbc_code] * Whatever you'd like to remove - be as specific as possible! For instance, don't use plain ol' `td`. That will literally remove every instance of a `td` on the page. Something like `div#stats td` would be more specific, and thus it would remove only what you want.

That will remove any and all divs with `id`'s of `omgdivid` - it doesn't matter if there is just one, or if there are 500 of them to remove, but typically you wouldn't use `.each()` for simply removing things.. The code below does the each same thing as the one above. [bbc_code]$('div#omgdivid').each(function () {
$(this).remove();
});[/bbc_code] * `this` refers to what you were initially referring to or using. In this case, it's `div#omgdivid`.

Also, try not to use `.hide()`. It appears to function exactly the same as `.remove()`, except the element is never actually removed from the page - it's simply turned invisible and cannot be seen (though it's still actually there). The `.remove()` function removes the element from the page entirely , not just hides it.
Joe
Off
Profile
Quote
Top
 
Oracle
Member Avatar
Level 8
So, does .each() mean get each div?
Visit my shop! Forum reviews, posting packages, recolors
Posted ImagePosted Image
Posted Image
Me!

Off
Profile
Quote
Top
 
Aidan
Member Avatar
Level 12
Outline Documentations
T H E M E S

Documentation accepted in to the Themes database
Off
Profile
Quote
Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Coding & Development · Next Topic »

Welcome Guest [Log In] [Register]
Outline Live
Loading..
Loading..