-
Hi, lets say we have index.html file and inside of the file we have bunch of components. Is there a way to access them in Leptos?For example by id of the component etc. <!DOCTYPE html>
<html>
<body>
<h1>Welcome</h1>
<button>This is a fine button</button>
</body>
</html> Is there a way to access this button from Leptos and add some functionality? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Yes and no. It is entirely possible to work with any old DOM element using the tools provided by Like any framework, Leptos works primarily by adding functionality to element that it creates. So we'd tend to think about mounting a Leptos application to a particular DOM element, rather than using Leptos to add some functionality to an existing DOM element. You'd do this by using It is also possible to just use some of the helper utilities included in Leptos to add an event listener or something to an existing button, but the lower level you go like this the less the framework is helpful. |
Beta Was this translation helpful? Give feedback.
Yes and no.
It is entirely possible to work with any old DOM element using the tools provided by
web-sys
, which provides a Rust interface for all DOM APIs. For example, can can easily candocument().get_element_by_id("...")
to get access to an element.Like any framework, Leptos works primarily by adding functionality to element that it creates. So we'd tend to think about mounting a Leptos application to a particular DOM element, rather than using Leptos to add some functionality to an existing DOM element. You'd do this by using
mount_to(some_element)
rather than the more generalmount_to_body()
, and it's completely possible.It is also possible to just use some of the helper utilities …