You are here: Reference > JavaScript > client-side > style handling > methods > setExpression (runtimeStyle, style)
setExpression method (runtimeStyle, style)
9 |
Sets a dynamic expression for the specified style property.
The support for dynamic properties has been removed in Internet Explorer 9, so none of the getExpression, removeExpression, setExpression and recalc methods are supported.
These methods exist in version 8, but using them raises exceptions.
Dynamic expressions (also called dynamic properties) provide a way to specify script expressions for the values of style properties.
These expressions are recalculated automatically, but if necessary, they can be explicitly updated with the recalc method.
Expressions can be set with the setExpression method in JavaScript or with the style expression method in CSS.
Dynamic expressions are also supported for the values of DHTML properties.
If you need further information about it, see the pages for the htmlObj.getExpression, htmlObj.removeExpression and htmlObj.setExpression methods.
To get an expression:
See the example below for details.
- use the getExpression method
- use the removeExpression method.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the name of the style property. Use the name of the corresponding JavaScript property (camelCase name) instead of the name of the CSS property. The corresponding JavaScript property names can be found on the pages for the CSS properties. This parameter is not case-sensitive. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. String that specifies the script expression for the value of the style property. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Optional. String that specifies the language of the expression script.
One of the following values:
|
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of dynamic expressions for style properties:
|
||||
<head> <script type="text/javascript"> // Try..catch blocks need to be used because of Internet Explorer 8 function GetExp () { var div = document.getElementById ("myDiv"); try { var expression = div.style.getExpression ("width"); alert ("Expression is: " + expression); } catch (e) { alert ("Your browser does not support the getExpression method!"); } } function SetExp () { var div = document.getElementById ("myDiv"); try { div.style.setExpression ("width","myInput.value + 'px'"); } catch (e) { alert ("Your browser does not support the setExpression method!"); } } function RemoveExp () { var div = document.getElementById ("myDiv"); try { div.style.removeExpression ("width"); } catch (e) { alert ("Your browser does not support the removeExpression method!"); } } </script> </head> <body> <div id="myDiv" style="background-color:blue; width:expression(myInput.value + 'px');"></div> <br /> The following value specifies the width of the blue element.<br /> Modify it and watch the blue element. <input type="text" id="myInput" value="40" /> <br /><br /><br /> With the following buttons you can get, remove and set the expression for the width style property of the blue element:<br /> <button onclick="GetExp ()">Get expression!</button> <button onclick="SetExp ()">Set expression!</button> <button onclick="RemoveExp ()">Remove expression!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
htmlElement.runtimeStyle, htmlElement.style
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