Mercurial > urweb
changeset 600:d1cce194180d
Do proper insertion of dynamic content within nested DOM containers
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 11 Jan 2009 10:41:38 -0500 |
parents | 889dc9fceb3a |
children | 7c3c21eb5b4c |
files | jslib/urweb.js tests/ooo.ur tests/ooo.urp |
diffstat | 3 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/jslib/urweb.js Sun Jan 11 10:22:19 2009 -0500 +++ b/jslib/urweb.js Sun Jan 11 10:41:38 2009 -0500 @@ -34,17 +34,26 @@ return s; } +function myParent() { + var pos = document; + + while (pos.lastChild && pos.lastChild.nodeType == 1) + pos = pos.lastChild; + + return pos.parentNode; +} + function dyn(s) { var x = document.createElement("span"); x.innerHTML = s.v; - document.body.appendChild(x); + myParent().appendChild(x); s.h = cons(function() { x.innerHTML = s.v }, s.h); } function inp(t, s) { var x = document.createElement(t); x.value = s.v; - document.body.appendChild(x); + myParent().appendChild(x); s.h = cons(function() { x.value = s.v }, s.h); x.onkeyup = function() { sv(s, x.value) }; }