# Onclick HTML attribute get stripped out in Code Mode

**URL:** <https://forum.mautic.org/t/onclick-html-attribute-get-stripped-out-in-code-mode/13764>\
**Category:** Product Support\
**Created:** [April 3, 2020, 3:09am UTC](https://forum.mautic.org/t/onclick-html-attribute-get-stripped-out-in-code-mode/13764 "2020-04-03T03:09:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![julien66](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/julien66/32/1033_2.png) [@julien66](https://forum.mautic.org/u/julien66)\
**Post date:** [April 3, 2020, 3:09am UTC](https://forum.mautic.org/t/onclick-html-attribute-get-stripped-out-in-code-mode/13764/1 "2020-04-03T03:09:45Z")

</div>

Hi Mautic community,

**Your software**  
My Mautic version is : 2.16.0  
My PHP version is: 7.1.33

**Your problem**  
My problem is:

While composing a landing page in Code Mode I want to capture events that hit some tags in order to attach Javascript functions.  
For example, I want to be able to have:  
Click Here  
(I want to do that to show a pop-up when someone clicks the link.)

The problem is that once I click on Apply in Code Builder, the part onclick=“myFunction()” attribute get stripped out from the HTML code.

Is there a way to keep the Javascript elements in Code Mode? May be by toggling some flag in the config files of Mautic?

Steps I have tried to fix the problem:  
I search in the Community Forum but found only hints related to the former editor Froala.

Thanks!  
Julien

---

<div class="post-metadata">

**Author:** ![renzof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/renzof/32/1738_2.png) [@renzof](https://forum.mautic.org/u/renzof)\
**Post date:** [April 3, 2020, 8:57am UTC](https://forum.mautic.org/t/onclick-html-attribute-get-stripped-out-in-code-mode/13764/2 "2020-04-03T08:57:31Z")

</div>

Hi,  
I can confirm this is happening and not sure how to solve it. What you can do as a workaround is to bind the even in javascript rather than adding it to the html.

For example  
`<button id="myBtn">Click here</button>`

Then the javascript would be something like this

```
<script>
document.getElementById("myBtn").onclick = function() {myFunction()};
</script>

```

[https://www.w3schools.com/jsref/event\_onclick.asp](https://www.w3schools.com/jsref/event_onclick.asp)

---

<div class="post-metadata">

**Author:** ![julien66](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/julien66/32/1033_2.png) [@julien66](https://forum.mautic.org/u/julien66)\
**Post date:** [April 3, 2020, 8:09pm UTC](https://forum.mautic.org/t/onclick-html-attribute-get-stripped-out-in-code-mode/13764/3 "2020-04-03T20:09:57Z")

</div>

Thank you @renzof !!

I didn’t though going this way, not a big pro in javascript.

When I tried the solution it didn’t work. I declared the script in the \<head\>. I realized it was because the element #myBtn was not created in the DOM when the script was parsed. So the script needs to be declared after the HTML element, for example right before \</body\> and that makes the trick.

---

<div class="post-metadata">

**Author:** ![renzof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/renzof/32/1738_2.png) [@renzof](https://forum.mautic.org/u/renzof)\
**Post date:** [April 3, 2020, 8:25pm UTC](https://forum.mautic.org/t/onclick-html-attribute-get-stripped-out-in-code-mode/13764/4 "2020-04-03T20:25:34Z")

</div>

Great!  
Glad to be of help 👍🏼
