[Web] How to modify <html> tag attributes programmatically? #4162
Unanswered
AndrewVetovitz
asked this question in
Q&A
Replies: 1 comment
-
Hello! To modify the attributes of the use web_sys::{wasm_bindgen::JsCast, HtmlElement};
let html_element = web_sys::window()
.expect("Window not found")
.document()
.expect("Document not found")
.document_element()
.expect("Document element not found")
.dyn_into::<HtmlElement>()
.expect("Failed to cast to HtmlElement"); Once you have the html_element
.set_attribute("data-theme", "dark")
.expect("Failed to set attribute"); I learned this approach while building Note: When using web-sys = { version = "0.3.77", features = [
"Document",
"Window",
"HtmlHeadElement",
]} Hope this helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I could not find anything in the documentation or examples online, but is there a programmatic way to set the <html> tag(s)?
I could do something like this example: https://github.com/DioxusLabs/dioxus/blob/main/examples/custom_html.rs
and set them this way by in-lining, but is there something I am missing?
It would be nice if there were something like document::Html {...} to set the tags directly.
Beta Was this translation helpful? Give feedback.
All reactions