# mousePressed not working with P5.Dom button creation

**URL:** https://discourse.processing.org/t/mousepressed-not-working-with-p5-dom-button-creation/3203
**Category:** p5.js
**Created:** [September 2, 2018, 8:16pm UTC](https://discourse.processing.org/t/mousepressed-not-working-with-p5-dom-button-creation/3203 "2018-09-02T20:16:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tmarasco125](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@tmarasco125](https://discourse.processing.org/u/tmarasco125)
#### Post date: [September 2, 2018, 8:17pm UTC](https://discourse.processing.org/t/mousepressed-not-working-with-p5-dom-button-creation/3203/1 "2018-09-02T20:17:00Z")

</div>

Hi! I just started using the newest version of p5.js and p5.dom.js, and the mousePressed() method throws an error when a DOM button is clicked. Here is my code:

```auto
var button;

function setup(){
noCanvas();
    button = createButton(" ");
    button.addClass("button button-primary button-border-thick button-box");
    button.mousePressed(logPress);
}

function draw(){

}

function logPress(){
console.log("Boing");
}

```

When the button is clicked, the console gives this error message:

> Uncaught TypeError: Cannot read property ‘\_setProperty’ of undefined  
> at g.Element. (p5.min.js:7)  
> (anonymous) @ p5.min.js:7

I was using version 0.7.1 of both p5.js and p5.dom.js, but when I switched p5 back to version 0.6.1, this worked perfectly. Has anyone else encountered this issue??

edit: Here is my index.html code as well

```auto
<!-- Buttons core css -->
<html>
    <head>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.1/p5.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.1/addons/p5.dom.min.js"></script>

    </head>
<style>
    body {
    background-color: #FFFF00 
}

</style>
<body>
    <script src="code.js"></script>
    </body> 
<link rel="stylesheet" href="css/buttons.css">
</html>

```

---

<div class="post-metadata">

### Author: ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)
#### Post date: [September 2, 2018, 8:46pm UTC](https://discourse.processing.org/t/mousepressed-not-working-with-p5-dom-button-creation/3203/2 "2018-09-02T20:46:18Z")

</div>

I did a little bit of reading around and I found [this](https://github.com/processing/p5.js/issues/3141). Seems like it has something to do with the version that you are using? I also can assume that it will be fixed sooner or later. I personally do not know much about p5, and how you could work around this issue, but I do know that in general you could make a button with HTML, and then use JavaScript and the `onclick()` function to do something similar?

Hopefully this helps,  
EnhancedLoop7

---

<div class="post-metadata">

### Author: ![tmarasco125](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@tmarasco125](https://discourse.processing.org/u/tmarasco125)
#### Post date: [September 2, 2018, 8:52pm UTC](https://discourse.processing.org/t/mousepressed-not-working-with-p5-dom-button-creation/3203/3 "2018-09-02T20:52:14Z")

</div>

Thank so much for pointing me to this. Looks like they’re fixing it for the next release ASAP. Thanks for the reminder on the `onclick()` function as well!

---

<div class="post-metadata">

### Author: ![EnhancedLoop7](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/enhancedloop7/32/1040_2.png) [@EnhancedLoop7](https://discourse.processing.org/u/EnhancedLoop7)
#### Post date: [September 2, 2018, 8:55pm UTC](https://discourse.processing.org/t/mousepressed-not-working-with-p5-dom-button-creation/3203/4 "2018-09-02T20:55:50Z")

</div>

It’s no problem! Glad I could help 😃

EnhancedLoop7
