Title: Adding Javascript attributes to buttons
Last modified: August 24, 2020

---

# Adding Javascript attributes to buttons

 *  Resolved [MisterChaos](https://wordpress.org/support/users/mattp225/)
 * (@mattp225)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/adding-javascript-attributes-to-buttons/)
 * Hi Tom,
 * I’m loving this plugin.
 * Quick question and possible feature request. With the buttons block, it would
   be really handy for me to be able to add certain Javascript triggers, for example,
   an onclick attribute to trigger modal popups and assorted things.
 * 1. Is this available already and I’m not seeing how to do it? If so, what are
   the steps?
 * 2. If it’s not already a feature, could we get this added in?
 * Cheers

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Tom](https://wordpress.org/support/users/edge22/)
 * (@edge22)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/adding-javascript-attributes-to-buttons/#post-13313670)
 * Hi there,
 * We have a custom attributes feature coming in the pro version, but it doesn’t
   include `onclick` at the moment for security purposes. I played with it a bit,
   and it’s a nightmare in the editor as well (you need to click the block to edit
   it).
 * It will allow you to add `data-*` attributes that you can use with to target 
   elements with javascript. Of course, you can use custom classes to do this right
   now in the free version.
 * Let me know if you need more info 🙂
 *  Thread Starter [MisterChaos](https://wordpress.org/support/users/mattp225/)
 * (@mattp225)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/adding-javascript-attributes-to-buttons/#post-13313755)
 * Got it, thanks.
 * I was using the button to trigger an email collection popup, which uses onclick…
   I thought it could be something as simple as adding an attribute to the block
   settings, sort of like it’s done with the CSS classes.
 * This helps, though. I’ll check the alternatives you suggested. Thanks again.
 *  Plugin Author [Tom](https://wordpress.org/support/users/edge22/)
 * (@edge22)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/adding-javascript-attributes-to-buttons/#post-13318318)
 * No problem!
 * Inline javascript can be a pain, better to do this:
 *     ```
       document.querySelector( '.my-button-class' ).addEventListener( 'click', function( e ) {
           // Do onclick stuff in here.
       } );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Adding Javascript attributes to buttons’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Tom](https://wordpress.org/support/users/edge22/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/adding-javascript-attributes-to-buttons/#post-13318318)
 * Status: resolved