_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

Cannot append to html element

Open mikemissing opened this issue 3 years ago • 4 comments

Hej, love the code, amazing work!

Now, to the issues - I am trying to append some text to a html element, below is POC code: <div _="on click append 'foo' to #bottom">Click</div><div id="bottom">Hello</div>

The script fails with undefined undefined error from line 1771 in the hyperscript.js file.

Looking deeper the error is actually: Unable to append to idRef from the parser.addCommand function.

Alternatively, the following code does not throw errors (although it does not achieve the same result): <div _="on click append 'foo' put it into #bottom">click</div><div id="bottom">Hello</div>

At this point I do not know enought about the inner working of hyperscript hence the issue ...

mikemissing avatar Jul 13 '21 09:07 mikemissing

Looks to me like you want something like this:

<div _="on click put 'foo' at end of #bottom">click</div><div id="bottom">Hello</div>

https://hyperscript.org/commands/put/

1cg avatar Jul 13 '21 18:07 1cg

Yes - @1cg 's suggestion is a good workaround, but "append" should work this way. I'm sorry it's not. It may be confusing #bottom with #bottom.innerHTML. I'll try to add a test case and patch when I can.

benpate avatar Jul 14 '21 16:07 benpate

Aww thanks for the prompt feedback! Keep up the good work.

mikemissing avatar Jul 20 '21 09:07 mikemissing

OMG, I finally did some work on this and my tests are passing. Let's hope my code is approved :)

benpate avatar Nov 09 '21 23:11 benpate