Skip to content

Commit

Permalink
utils: Add body() and document_element() getters (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Oct 26, 2021
1 parent 53c6425 commit 5b67085
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ version = "0.3"
features = [
"Document",
"History",
"HtmlElement",
"Location",
"Window"
]
12 changes: 12 additions & 0 deletions crates/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ pub fn document() -> web_sys::Document {
window().document().expect_throw("Can't find document")
}

/// Convenience function to access `document.body`.
pub fn body() -> web_sys::HtmlElement {
document().body().expect_throw("Can't find document body")
}

/// Convenience function to access `document.documentElement`.
pub fn document_element() -> web_sys::Element {
document()
.document_element()
.expect_throw("Can't find document element")
}

/// Convenience function to access the web_sys history.
pub fn history() -> web_sys::History {
window().history().expect_throw("Can't find history")
Expand Down

0 comments on commit 5b67085

Please sign in to comment.