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>
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>
@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:
<script>
$(function(){
$('#insertToggleButton').on('click', function(){
toggleInsert1();
});
});
</script>
If this answer helped, please, mark as solved ![]()
tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.
Drop by and say Hi to me on slack.
I also found that comments inside my JS caused HubSpot to make the entire function a comment ![]()
@tjoyceThanks for your Help.
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:
<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
Thanks @Jsum
Thanks, But that didn’t work either. Causing an exception.
@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.
$(function{ x
$(‘#insertToggleButton’).on(‘click’, function(){
toggleInsert1();
});
});
Uncaught SyntaxError: Unexpected token {
the x is where chrome indicated an error
@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.