clearAttributes method
Clears all attributes from the current element, except the id, name, style, value and event attributes.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the clearAttributes method:
|
||||
<head> <script type="text/javascript"> function ClearAttrs () { var marquee = document.getElementById ("myMarquee"); if (marquee.clearAttributes) { marquee.clearAttributes (); } else { for (var i = marquee.attributes.length - 1; i >= 0; i--) { var attr = marquee.attributes[i]; if (attr.name.toLowerCase () == "id") { continue; } if (attr.name.toLowerCase () == "style") { continue; } if (attr.name.substring (0,2).toLowerCase () == "on") { continue; } marquee.removeAttribute (attr.name, 0); } } } </script> </head> <body> <marquee id="myMarquee" bgcolor="red" onclick="alert ('Click event occurred!')" style="border:2px solid blue;">I am a marquee!</marquee> <br /><br /> <button onclick="ClearAttrs ();">Remove the attributes of the marquee.</button> <br /> Note: only the bgcolor attribute of the marquee can be removed with the button above. </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CommentNode
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, 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:reset, input:submit, input:text, ins, isindex, kbd, 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