# Make HTML button run custom node JS code

**URL:** <https://discourse.nodered.org/t/make-html-button-run-custom-node-js-code/47170>\
**Category:** Developing Nodes\
**Created:** [15 June 2021 10:50 UTC](https://discourse.nodered.org/t/make-html-button-run-custom-node-js-code/47170 "2021-06-15T10:50:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Belfving](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/belfving/32/43332_2.png) [@Belfving](https://discourse.nodered.org/u/Belfving)\
**Post date:** [15 June 2021 10:50 UTC](https://discourse.nodered.org/t/make-html-button-run-custom-node-js-code/47170/1 "2021-06-15T10:50:43Z")

</div>

So the problem is quite simple. I have made a custom node that continually saves it's state into the node context. What I want to do is have a button in the edit dialog box that will run a function I have created in the JS for the node, the goal here being resetting these context variables. In essence I would have to create the button in the HTML file and define it's functionality somewhere in the javascript.

Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 June 2021 11:11 UTC](https://discourse.nodered.org/t/make-html-button-run-custom-node-js-code/47170/2 "2021-06-15T11:11:19Z")

</div>

You create a HTTP Endpoint in the JS file and call to it from the HTML file. Take a look at the serial node in the Node red github repository for an example.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 August 2021 11:12 UTC](https://discourse.nodered.org/t/make-html-button-run-custom-node-js-code/47170/3 "2021-08-14T11:12:00Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
