Search code examples
javascriptgwt

setProperty is not a function(...)


When I use

$wnd.document.getElementById('id');

It works successfully and I get the element. But, when I try to set property like this:

$wnd.document.getElementById('id').setProperty("Property","value"); 

It brings me error :

Uncaught TypeError: $wnd.document.getElementById(...).setProperty is not a function(…)

With what mistake in my code can it be chained?


Solution

  • It looks like you are executing this code inside a JSNI method, means it is Javascript. The method setProperty is only available for a javascript style element, and has nothing todo with the GWT method setPropertyString() or similar.

    So this:

    elem =$wnd.document.getElementById('id');  
    elem[property] = value;
    

    equals this:

    $wnd.document.getElementById('id').setAttribute("property","value");
    

    setProperty would work for Style properties like this:

    $wnd.document.getElementById('id').style.setProperty("color","blue");