removeNode method
Removes the current element with or without its children from the document tree.
If you want to remove an element with its children, use the cross-browser removeChild method instead.
Example 2 demonstrates a cross-browser solution to remove an element without its children.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required in Opera and optional in Internet Explorer. Boolean that specifies whether child elements of the current element should also be removed.
One of the following values:
|
Return value:
Returns the removed element.
Example HTML code 1:
This example illustrates the use of the removeNode method:
|
||||
<head> <script type="text/javascript"> function RemoveBold () { var boldTag = document.getElementById ("bold"); if (boldTag) { if (boldTag.removeNode) { boldTag.removeNode (false); } else { alert ("Your browser does not support the removeNode method!"); } } } </script> </head> <body> <b id="bold"> Some text in bold <span style="color:red">Some red text in bold</span> </b> <br /><br /> <button onclick="RemoveBold ();">Remove the bold style!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates a cross-browser solution for the previuos one:
|
||||
<head> <script type="text/javascript"> function RemoveElement (element) { while (element.firstChild) { element.parentNode.insertBefore (element.firstChild, element); } element.parentNode.removeChild (element); } function RemoveBold () { var boldTag = document.getElementById ("bold"); if (boldTag) { RemoveElement (boldTag); } } </script> </head> <body> <b id="bold"> Some text in bold <span style="color:red">Some red text in bold</span> </b> <br /><br /> <button onclick="RemoveBold ();">Remove the bold style!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CommentNode, TextNode
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments