Search code examples
javascriptcssxulrunner

How to assign a percentage to a property of CSSStyleDeclaration


I work on an Eclipse RCP application having a HTML editor using XULRunner. In the JavaScript code interacting with the editor, I want to set the maximum width of an element using CSSStyleDeclaration.maxWidth:

/* node is an HTMLImageElement */
node.style.maxWidth = "100%";

The code above fails with the following message

Warning: Error in parsing value for property 'max-width'.  Declaration dropped.

But if I use pixels, it works:

node.style.maxWidth = "100px";

What is the correct syntax to set the CSS max-width property to 100%?


Solution

  • Try with

    node.style.maxWidth = '100%';