Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #233069

    Peter G
    Participant

    Hi Guys,

    May I please ask you how I can attach some JavaScript code to the buttons that are built into the theme?

    Thanks,

    Peter

    #233215

    Rue Nel
    Moderator

    Hello Peter,

    Thanks for posting in!

    The safest way to do it is by adding an “id” in your button. If you are using a shortcode, it should look like this, [button id="my-button" shape="square" size="mini" float="none" info="none" info_place="top" info_trigger="hover"]this is the button[/button]. And if you are using a visual composer, you can add the id by editing you button settings just like this, http://prntscr.com/6k8lx4

    Once you have your button id setup, you can use the custom javascript section from the customizer, Appearance > Customize > Custom > Javascript to insert your code. You can easily attach your custom javascript script to the button like this code:

    jQuery('#my-button').click( function(){
       // do something here
    });

    Hope this helps.

    #233448

    Peter G
    Participant

    Yes, it’s very helpful, thanks so much 🙂

    #233510

    Nico
    Moderator

    You’re most welcome!

    Let us know if you need anything else.

    Cheers!