2.3.2.3 removeAttribute

Removes an attribute from an object.

Syntax

 bSuccess = object.removeAttribute(sAttrName [, iCaseSensitive])

Parameters

sAttrName of type DOMString

A required string that specifies an attribute name.

iCaseSensitive of type integer

Optional. Integer that specifies whether to use a case-sensitive search to locate the attribute. Can be one of the following values:

1

The case of sAttrName is respected.

0

Match sAttrName regardless of case.

Return Value

Returns a Boolean with one of the following possible values:

true

The attribute was successfully removed.

false

The attribute was not removed.

Remarks

If your pages are displayed in IE7 mode, be careful when spelling attribute names. If two or more attributes have the same name—differing only in capitalization—and iCaseSensitive is set to 0, this method removes only the last attribute created with this name. All other attributes of the same name are ignored.

Example

The following examples demonstrate how to use the getExpression method to retrieve CSS properties.

This example uses the getExpression method to retrieve the width property of a span object.

 <body>
 <span id="trueBlueSpan" 
     style="background-color:lightblue; width:100px">
     The width of this blue span is set inline at 100 pixels.
 </span>
 <span id="oldYellowSpan" style="background-color:lightyellow; 
     width:200px">
     The width of this yelllow span is set inline at 200 pixels.
 </span>
 <br>
 <span id="AlGreenSpan" style="background-color:lightgreen; 
     width:expression(trueBlueSpan.style.pixelWidth + 
     oldYellowSpan.style.pixelWidth)">
     Click the button below to see the expression used to set 
     the width of this span.
 </span>
 <br>
 <button onclick=alert(AlGreenSpan.style.getExpression("width"));>
     See Expression</button>
 </body>

In the following example, the setExpression method is used to set the width property of a blue input type=text object equal to the sum of the values in two other input type=text objects. When the user clicks the input type=button element, the getExpression method is used to display the expression.

 <html>
 <head>
 <script language="JScript">
 var s;
 function fnInit() {
 Box3.style.setExpression("width","eval(Box1.value) + eval(Box2.value)",
 "jscript");
 }
 function getexp() {
 s=Box3.style.getExpression("width");
 alert("Expression for the width of the blue box is \n\n" + s + 
 "\n\nThe width property has a value of " + Box3.style.width);
 }
 </script>
 </head>
 <body onload=fnInit();>
 <input type=text id="Box1" value=40>
 <br><input type=text id="Box2" value=40>
 <br><input type=text id="Box3" style="background-color:blue">
 <br><input type=button id="Button2" value="Get expression" onclick="getexp()">
 </body>
 </html>
Show: