Skip to content

How to add reactive attribute to existing node? (and how to add innerText?) #260

Answered by Tao-VanJS
Morthe asked this question in Q&A
Discussion options

You must be logged in to vote

I think probably the most straightforward way is to define an side-effect for the purpose:

const reactive = van.state("VALUE")
van.derive(() => document.getElementById("DIV-01").setAttribute("data-reactive", reactive.val))
// Similar, for `innerText`
van.derive(() => document.getElementById("DIV-01").innerText = reactive.val)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Morthe
Comment options

Answer selected by Tao-VanJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants