removeAttribute method
Removes the attribute with the specified name from the current element.
If you need the removed attribute as an attribute node, use the removeNamedItem method.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the name of the attribute to remove.
If you want to remove an HTML attribute, then use the name of the HTML attribute in Firefox, Opera, Google Chrome, Safari and in Internet Explorer from version 8.
In Internet Explorer earlier than version 8, the corresponding JavaScript property name (camelCase name) needs to be specified.
The corresponding JavaScript property names can be found on the pages for the HTML attributes.
These names are usually identical, except in the following cases:
|
||||||||||||||||||||||||||||
|
Optional. Integer that specifies the case-sensitivity for the name of the attribute. This parameter is only supported in Internet Explorer earlier than version 8.
One of the following values:
|
Return value:
In Firefox, Opera, Google Chrome and Safari, the removeAttribute method has no return value.
In Internet Explorer, it returns a Boolean, one of the following values:
The attribute was not removed. | |
The attribute was removed. |
Methods for attributes without namespaces:
Name | Browser | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createAttribute | Creates a new attribute node with the specified name. | |||||||||||
getAttribute | Returns the value of the attribute with the specified name from the current element. | |||||||||||
getAttributeNode | Returns the attribute node with the specified name from the current element. | |||||||||||
getNamedItem | Returns the attribute node with the specified name from the current attributes collection. | |||||||||||
hasAttribute |
|
Returns whether the current element has an attribute with the specified name or not. | ||||||||||
removeAttribute | Removes the attribute with the specified name from the current element. | |||||||||||
removeAttributeNode | Removes the specified attribute node from the current element. | |||||||||||
removeNamedItem | Removes the attribute with the specified name from the current attributes collection and returns the removed attribute node. | |||||||||||
setAttribute | Adds an attribute with the specified name and value to the current element. | |||||||||||
setAttributeNode | Adds the specified attribute node to the current element. | |||||||||||
setNamedItem | Adds the specified attribute node to the current attributes collection. |
Example HTML code 1:
This example illustrates the use of the removeAttribute method:
|
||||
<head> <script type="text/javascript"> function DelStyle () { var div = document.getElementById ("myDiv"); div.removeAttribute ("style"); } </script> </head> <body> <div id="myDiv" style="background:red;">Division element with style.</div> <br /><br /> <button onclick="DelStyle ()">Remove the style attribute from the division element</button> </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, 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:search, 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:
removeAttributeNS
createAttribute
getAttribute
getAttributeNode
getNamedItem
hasAttribute
removeAttributeNode
removeNamedItem
setAttribute
setAttributeNode
setNamedItem
createAttribute
getAttribute
getAttributeNode
getNamedItem
hasAttribute
removeAttributeNode
removeNamedItem
setAttribute
setAttributeNode
setNamedItem
External links:
User Contributed Comments