Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IHTMLElement2::setExpression method

This element is obsolete and should no longer be used. Sets an expression for the specified object.


Integer setExpression(
  [in]           String sPropertyName,
  [in]           String sExpression,
  [in, optional] String sLanguage = JScript


sPropertyName [in]

String that specifies the name of the property to which expression is added.

sExpression [in]

String that specifies any valid script(JScript, JavaScript, VBSCript) statement without quotations or semicolons. This string can include references to other properties on the current page. Array references are not allowed on object properties included in this script.

sLanguage [in, optional]

String that specifies one of the following values:


Default. Language is JScript.


Language is VBScript.


Language is JavaScript.


Use the setExpression method to add expressions to supported Cascading Style Sheets (CSS) attributes and read/write DHTML Properties. To remove expressions set by setExpression, use the removeExpression method.

The following syntax sections show how to set an expression on DHTML Properties and CSS attributes.

  • Use this syntax to set an expression on a read/write property or on an expando property.
    object.setExpression(sPropertyName, sExpression, sLanguage)
  • Use this syntax to set an expression on a CSS attribute., sExpression, sLanguage)
  • Use the expression() syntax to set an expression on a CSS attribute in HTML.
    <element style="sAttributeName:expression(sExpression)">

The data type of the evaluated expression in the language parameter must match one of the possible values allowed for the expression parameter. If the property or attribute specified by the first parameter requires a string, the data type of the second parameter must be a string. Otherwise, the second parameter is evaluated prior to invoking setExpression, causing the expression to be set to the result of the evaluation.

Use the uniqueID property of an object in an expression to refer back to the object. Using uniqueID is an alternative to specifying an id for expressions that use an object reference.

The cssText property is a unique property that is not compatible with the dynamic properties implementation. Do not use cssText with any dynamic property methods.

The following examples illustrate common problems encountered with the expression parameter in setExpression. The expression appears valid, but may not be.

  • The provided expression is invalid because is "npx" and will not add to 13"height"," + 13"); 
  • The provided expression is invalid when is previously unspecified"width",""); 


The following examples use the setExpression method to change the width of a blue box. In each example, the width of the blue box is equal to the sum of the values of the first two text boxes. When a value in one of the text boxes changes, the width of the blue box recalculates.

This example shows the HTML implementation of setExpression.

Code example:

<!DOCTYPE html>
  <title>Dynamic Properties Sample</title>

  <h1>Inline Dynamic Properties Sample</h1>
  <input type="text" id="box1" value="40" style="width: 40px;"> The sum of the values in these two text boxes determines the width<br>
  <input type="text" id="box2" value="40" style="width: 40px;"> of the blue text box below.<br>
  <input type="text" id="box3" style="background-color: blue; width: 80px;">
    var box1 = document.getElementById('box1');
    var box2 = document.getElementById('box2');
    var box3 = document.getElementById('box3');

    box1.addEventListener('change', eventHandler, false)
    box2.addEventListener('change', eventHandler, false)

    function eventHandler(evt) {
      newWidth = parseInt(box1.value) + parseInt(box2.value) + "px";
      if ( {'width', newWidth, 'JavaScript');
      else {'width', newWidth);

See also

About Dynamic Properties



© 2017 Microsoft