question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTMLElement.style.setAttribute throw style.setAttribute is not a function

See original GitHub issue

GWT version : 2.8.2 elemental2 version : 1.0.0-RC1

using the setAttribute from elemental2 CSSStyleDeclaration gives is not a function, while using setProperty works.

to repeat the case add the following code snippet

HTMLElement element= (HTMLElement) DomGlobal.document.createElement("div");
element.style.setProperty("padding-left","10px");//works
element.style.setAttribute("padding-right","10px");//fail

DomGlobal.document.body.appendChild(element);

the exception

App.java:13 Uncaught TypeError: element_0_g$.style.setAttribute is not a function
    at wzd_g$.xzd_g$ [as onModuleLoad_0_g$] (App.java:13)
    at Array.crb_g$ (org_00046sample_0004…MethodHolder.java:3)
    at initializeModules_0_g$ (ModuleUtils.java:44)
    at Dp_g$ (Impl.java:309)
    at Gp_g$ (Impl.java:368)
    at Impl.java:78
    at wqb_g$ (ModuleUtils.java:55)
    at App.java:9

i noticed that in the MDN documentation there is no setAttribute method https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration

if it is something need to be fixed and i can make a PR for, i will gladly do. Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
niloc132commented, Apr 17, 2018

This will be much easier to notice by elemental2 users if https://github.com/google/jsinterop-generator/pull/6 is accepted, so that the @Deprecated is on the java types as well.

0reactions
gkdncommented, Apr 17, 2018

Ok that’s actually what they did so I think we can close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: setAttribute is not a function in JavaScript
To solve the "setAttribute is not a function" error, make sure to only call the setAttribute method on valid DOM elements and place...
Read more >
element.setAttribute is not a function - Stack Overflow
In that case, the element doesn't exist yet in the document. You need to run the code after the element is created, say...
Read more >
Uncaught TypeError on setting attribute in JavaScript
In this approach, you may get an Uncaught TypeError saying “elem.setAttribute is not a function”. This happens because you are trying to call ......
Read more >
HTML DOM Element setAttribute() Method - W3Schools
Definition and Usage. The setAttribute() method sets a new value to an attribute. If the attribute does not exist, it is created first....
Read more >
Use of SetAttribute() in JavaScript with Examples - eduCBA
In the function, we are getting the item using 'document.getElementById(“button”)'; Then we are adding to attribute value style and background color as yellow ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found