diff --git a/listener.js b/listener.js index fc381a3..24c4ed7 100644 --- a/listener.js +++ b/listener.js @@ -45,7 +45,10 @@ export const bind = (listener, prop, target=document.createTextNode(""), filter) ? filter(data) : data if ("innerText" in target) - target.innerText = data + if (typeof data == "string") + target.innerText = data + else + target.replaceChildren(data) else target.data = data } diff --git a/listener.md b/listener.md index f198ac0..3d31336 100644 --- a/listener.md +++ b/listener.md @@ -22,7 +22,9 @@ bind(listener, "value") bind(listener, "value", html_element) // Binds an existng HTML or Text node bind(listener, "value", html_element, value => value.toUpperCase()) -// Filters the value through a function before setting it +// Accepts a function to transform the value +bind(listener, "value", html_element, value => document.createElement("hr")) +// Also accepts HTML elements when the target is not a text node ``` ## Example