# Using HTML button element to change a variable in the Javascript

**URL:** <https://discourse.processing.org/t/using-html-button-element-to-change-a-variable-in-the-javascript/47557>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [November 22, 2025, 4:40pm UTC](https://discourse.processing.org/t/using-html-button-element-to-change-a-variable-in-the-javascript/47557 "2025-11-22T16:40:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![telstartelstar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/telstartelstar/32/21263_2.png) [@telstartelstar](https://discourse.processing.org/u/telstartelstar)\
**Post date:** [November 22, 2025, 4:40pm UTC](https://discourse.processing.org/t/using-html-button-element-to-change-a-variable-in-the-javascript/47557/1 "2025-11-22T16:40:55Z")

</div>

Hi again!  
For another part of my project I’m trying to figure out how to use a element in the HTML of my sketch to change a set variable in my Javascript. In specific I’m using it to change the background image variable of the Javascript, but I’m not finding anything in the documentation that helps me figure out what to put in the “onclick=” part of the element that can lead it to the variable in my javascript.  
I’m wondering if it’s even a possibility at this point, but I’m very stumped at this part.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 22, 2025, 5:46pm UTC](https://discourse.processing.org/t/using-html-button-element-to-change-a-variable-in-the-javascript/47557/2 "2025-11-22T17:46:00Z")

</div>

If your element is pre-defined in your HTML file, you can use **select()** to find it:

> **[select](https://p5js.org/reference/p5/select/)**
>
> select

And then invoke method **mousePressed()** over the found element in order to add a callback to it:

> **[mousePressed](https://p5js.org/reference/p5.Element/mousePressed/)**
>
> mousePressed

---

<div class="post-metadata">

**Author:** ![telstartelstar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/telstartelstar/32/21263_2.png) [@telstartelstar](https://discourse.processing.org/u/telstartelstar)\
**Post date:** [November 23, 2025, 1:38am UTC](https://discourse.processing.org/t/using-html-button-element-to-change-a-variable-in-the-javascript/47557/3 "2025-11-23T01:38:42Z")

</div>

I see, would it also be possible to use this to control a camera’s position?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 23, 2025, 1:55am UTC](https://discourse.processing.org/t/using-html-button-element-to-change-a-variable-in-the-javascript/47557/4 "2025-11-23T01:55:24Z")

</div>

You mean this 1:

> **[createCamera](https://p5js.org/reference/p5/createCamera/)**
>
> createCamera

> **[p5.Camera](https://p5js.org/reference/p5/p5.Camera/)**
>
> p5.Camera
