# Whether the "onclick" event works in sidebar?

**URL:** <https://discourse.mozilla.org/t/whether-the-onclick-event-works-in-sidebar/26287>\
**Category:** Development\
**Created:** [March 5, 2018, 12:32pm UTC](https://discourse.mozilla.org/t/whether-the-onclick-event-works-in-sidebar/26287 "2018-03-05T12:32:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![d11](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@d11](https://discourse.mozilla.org/u/d11)\
**Post date:** [March 5, 2018, 12:32pm UTC](https://discourse.mozilla.org/t/whether-the-onclick-event-works-in-sidebar/26287/1 "2018-03-05T12:32:04Z")

</div>

Hi!

In Mozilla add-ons (created with WebExtention) I need put some button on the sidebar and add “onclik” event on it.  
I wrot simple code in sidebar HTML file:

```
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="panel.css"/>
  </head>
<body>
 <h2 style="text-align: center">Pages</h2>
 <form action="">
  <input id="bttn" type="button" value="Prev" onclick="showNext()">
 </form>
 <script src="panel.js"></script>
</body>
</html>

```

where file panel.js has such content:

```
function showNext() {
	alert("ok");	
}

```

But when I press button “Prev”, “alert” window, doesn’t appear.  
I have tried to make even more simply and used only sidebar HTML file:

```
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="panel.css"/>
  </head>
<body>
 <h2 style="text-align: center">Pages</h2>
 <form action="">
  <input id="bttn" type="button" value="Prev" onclick="alert("ok")">
 </form>
 <script src="panel.js"></script>
</body>
</html>

```

…same result (

What wrong?

P.S. sidebar is shown correctly

 ![%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5](https://us1.discourse-cdn.com/flex001/uploads/mozilla/original/3X/a/0/a057feb6112a8aeb289a0daa55ec68f8c4f27253.png)

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [March 5, 2018, 2:12pm UTC](https://discourse.mozilla.org/t/whether-the-onclick-event-works-in-sidebar/26287/2 "2018-03-05T14:12:05Z")

</div>

Inline scripts (including on\* event attributes) are not allowed in extensions. Add your listener in your JS with `addEventListener` instead.

---

<div class="post-metadata">

**Author:** ![d11](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@d11](https://discourse.mozilla.org/u/d11)\
**Post date:** [March 6, 2018, 4:41am UTC](https://discourse.mozilla.org/t/whether-the-onclick-event-works-in-sidebar/26287/3 "2018-03-06T04:41:33Z")

</div>

Many thanks, Martin!
