-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot set HTMLElement.style properties #132
Comments
This is a limitation of the current API design of JavaScriptKit. var style = spanElem.style
style.backgroundColor = "yellow"
spanElem.style = style Even I'll re-design JavaScriptKit API to resolve this semantics mismatch, but please use this workaround to avoid re-assignment for a while. Sorry. import JavaScriptKit
let document = JSObject.global.document
var spanElem = document.createElement("span")
spanElem.innerText = "hello"
var style = spanElem.style as JSValue
style.backgroundColor = "yellow"
_ = document.body.appendChild(spanElem) |
Thank you for your very helpful response! With it I'm no longer stuck and can continue with my project. :) One note:
I had to write
This problem pops up here and there. Maybe a re-design could also alleviate this small annoyance? If there's already a document or issue use to gather such input I'd be happy to contribute this observation (and some others) there! |
I have this really simple problem I can't seem to figure out. I'm trying to use
JavaScriptKit
to create an element in the browsers DOM and set some CSS style on it:But it seems that the assignment to
spanElem.style.backgroundColor
doesn't have any effect. When I run this code (asmain.swift
), the<span>
is created but its CSS style is unchanged. Readingstyle.backgroundColor
from the browser console also shows nothing, but changing it from there works as expected:I'm using carton 0.10.0, Swift swift-wasm-5.3.1-RELEASE, JavaScriptKit 0.10.1 and am testing with newest Chrome and Safari (with same results) on macOS 10.15.7.
What am I doing wrong here?
The text was updated successfully, but these errors were encountered: