"Adam D. Ruppe" <destructiona...@gmail.com> wrote in message news:iqua65$rm2$1...@digitalmars.com... > > auto f = cast(Form) document.getElementById("code-runner"); > f.setValue("code", `void main() { assert(0, "Hello, world!"); }`); >
Minor suggestion: There should be an overload of getElementById that's defined like this: T getElementById(T)(string str) if(is(T:WhateverYourBaseNodeTypeIs)) { auto node = cast(T) getElementById(str); if(node) return node; else throw new ElementNotFoundException(T.stringof, str); } class ElementNotFoundException : Exception { this(string type, string str) { super("Element of type '"~type~"' matching '"~str~"' not found."); } } That way if it's missing, you get an accurate message instead of an awful null pointer exception. Or maybe call it requireElementById. Or, of course, if it's in a class and can't have templated members (I really hate that limitation. Templated class members would be so much more useful than being able to ship .obj's and .lib's without the original source), then: T getElementById(T)(WhateverYourBaseNodeTypeIs root, string str) if(is(T:WhateverYourBaseNodeTypeIs)) { ... } And, of course, just use the original getElementById if you want to allow the element to be optional. Another separate thought: What happens if you want to (or try to) put the same data in more than one place? Maybe there should be a way to detect and error if there's more than one of the same thing. Or maybe better yet, getElementById could return a special collection that contains all matching elements. And it could expose the same interface as a single element, but automatically applies it to all matched elements. Of course, you couldn't use "id=" for that since that's really not supposed to have duplicates. So you'd have to use "class=" instead. Which opens the possibility, if you're not doing this already, for the HTML importing (and maybe the DOM, too, or at least serializing the DOM at the end) to detect and error on multiple instances of the same "id=".