# Onlcick is stripped from my code

**URL:** <https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009>\
**Category:** CMS Development\
**Created:** [August 29, 2018, 7:47pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009 "2018-08-29T19:47:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![fayettec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fayettec/32/9373_2.png) [@fayettec](https://community.hubspot.com/u/fayettec)\
**Post date:** [August 29, 2018, 7:47pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/1 "2018-08-29T19:47:35Z")

</div>

When I add this to my html,

\<button onclick=‘toggleInsert1()’ id=“insertToggleButton”\>See Analytics\</button\>

I get this after i save it

\<button id=“insertToggleButton”\>See Analytics\</button\>

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 29, 2018, 7:51pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/2 "2018-08-29T19:51:33Z")

</div>

@fayettec - If you’re adding it in a wysiwyg, hubspot does some things to sanitize the html and maintain scopes of javascript (mostly seen in embed codes but, could be happening in this scenario as well). It’s best to use the following code:

```auto
<script>
$(function(){
 $('#insertToggleButton').on('click', function(){
 toggleInsert1();
 });
});
</script>

```

* * *

If this answer helped, please, mark as solved 😄

* * *

[tim@belch.io](mailto:tim@belch.io) | [forms.belch.io](https://forms.belch.io) | Design your own Beautiful HubSpot Forms; No coding necessary.

Drop by and say Hi to me [on slack](http://slack.belch.io/).

---

<div class="post-metadata">

**Author:** ![fayettec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fayettec/32/9373_2.png) [@fayettec](https://community.hubspot.com/u/fayettec)\
**Post date:** [August 29, 2018, 8:22pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/3 "2018-08-29T20:22:33Z")

</div>

I also found that comments inside my JS caused HubSpot to make the entire function a comment 😞

---

<div class="post-metadata">

**Author:** ![fayettec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fayettec/32/9373_2.png) [@fayettec](https://community.hubspot.com/u/fayettec)\
**Post date:** [August 29, 2018, 8:24pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/4 "2018-08-29T20:24:06Z")

</div>

@tjoyceThanks for your Help.

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [August 29, 2018, 7:58pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/5 "2018-08-29T19:58:25Z")

</div>

@fayettec,

It does sound like you are trying to put the code in the the source code for a richtext area. I know that the rich text editor has rules for it’s markup and will manipulate mark up to match those rules. \<a\> tags with out the “href” attribute are removed as well.

You can use jquery to insert the onlclick on page load like @tjoyce said, you can write an onclick function that targets a unique class on the button:

```auto
<button class="the_button">click</button>

$('.the_button').on('click touch', function(){

});

```

or you can find a way to hard code the button, such as by using a custom module.

Need help? [Hire Us Here](https://www.upwork.com/o/companies/_~0124e15ff34efb3871/)

---

<div class="post-metadata">

**Author:** ![fayettec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fayettec/32/9373_2.png) [@fayettec](https://community.hubspot.com/u/fayettec)\
**Post date:** [August 29, 2018, 8:25pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/6 "2018-08-29T20:25:19Z")

</div>

Thanks @Jsum

---

<div class="post-metadata">

**Author:** ![fayettec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fayettec/32/9373_2.png) [@fayettec](https://community.hubspot.com/u/fayettec)\
**Post date:** [August 29, 2018, 7:59pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/7 "2018-08-29T19:59:55Z")

</div>

Thanks, But that didn’t work either. Causing an exception.

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 29, 2018, 8:01pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/8 "2018-08-29T20:01:50Z")

</div>

@fayettec - It would help to see the full JS error or a preview link to the page causing the issues. The error is probably unrelated to your original issue.

---

<div class="post-metadata">

**Author:** ![fayettec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/fayettec/32/9373_2.png) [@fayettec](https://community.hubspot.com/u/fayettec)\
**Post date:** [August 29, 2018, 8:08pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/9 "2018-08-29T20:08:08Z")

</div>

$(function{ x  
$(‘#insertToggleButton’).on(‘click’, function(){  
toggleInsert1();  
});  
});

Uncaught SyntaxError: Unexpected token {

the x is where chrome indicated an error

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [August 29, 2018, 8:09pm UTC](https://community.hubspot.com/t/onlcick-is-stripped-from-my-code/10009/10 "2018-08-29T20:09:46Z")

</div>

@fayettec - My apologies, I forgot a syntax in the code (it was untested). I updated my original answer if you can copy the code again.
