# Returning list of html elements from javascript

**URL:** <https://swi-prolog.discourse.group/t/returning-list-of-html-elements-from-javascript/7202>\
**Category:** Help!\
**Tags:** bug, wasm\
**Created:** [January 28, 2024, 7:48pm UTC](https://swi-prolog.discourse.group/t/returning-list-of-html-elements-from-javascript/7202 "2024-01-28T19:48:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjano314](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mjano314/32/2621_2.png) [@mjano314](https://swi-prolog.discourse.group/u/mjano314)\
**Post date:** [January 28, 2024, 7:48pm UTC](https://swi-prolog.discourse.group/t/returning-list-of-html-elements-from-javascript/7202/1 "2024-01-28T19:48:09Z")

</div>

There seems to be an error. If there is just one “a” element on the document, this:

```prolog
List := 'Array'.from(document.getElementsByTagName("a")).

```

returns list with one element `[<js_HTMLAnchorElement>(1)]`, which is correct.  
If there are more “a” elements, variable `List` remains unbound.

I think the issue could be in `src/wasm/prolog.js`, related to variable `term` and line

```prolog
rc = prolog.bindings.js_unify_obj(term, id);

```

In the first call (which is the last element of Array) the `term` is unbound with `id=1` and `js_unify_obj` succeeds. The second call with the last but one element the `term` is already bound to this last Array’s element and `js_unify_obj` fails.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [January 29, 2024, 8:41am UTC](https://swi-prolog.discourse.group/t/returning-list-of-html-elements-from-javascript/7202/2 "2024-01-29T08:41:28Z")

</div>

> [@mjano314](#):
>
> The second call with the last but one element the `term` is already bound to this last Array’s element and `js_unify_obj` fails.

Correct! Pushed a fix with 51e8638028649ba27f48394af708fbfb5b7170b0. Thanks!
