Open
Description
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:
import JavaScriptKit
let document = JSObject.global.document
var spanElem = document.createElement("span")
spanElem.innerText = "hello"
spanElem.style.backgroundColor = "yellow"
_ = document.body.appendChild(spanElem)
But it seems that the assignment to spanElem.style.backgroundColor
doesn't have any effect. When I run this code (as main.swift
), the <span>
is created but its CSS style is unchanged. Reading style.backgroundColor
from the browser console also shows nothing, but changing it from there works as expected:
document.getElementsByTagName('span')[0].style.backgroundColor
""
document.getElementsByTagName('span')[0].style.backgroundColor = "yellow"
"yellow"
document.getElementsByTagName('span')[0].style.backgroundColor
"yellow"
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?
Metadata
Assignees
Labels
No labels