How can I start a Webflow interaction using custom JS code with only the data-w-id?

TL;DR
  • Inspect the webpage to locate the element with the specific data-w-id.
  • Add custom JavaScript in Webflow's project settings with the given snippet to trigger the interaction by specifying the data-w-id.
  • Publish and test your site to ensure the interaction launches correctly.

To start a Webflow interaction using custom JavaScript code with only the data-w-id, follow these steps to trigger interactions programmatically.

1. Identify the Element with the data-w-id

  • Inspect the webpage in your browser.
  • Locate the element that has the specific data attribute (data-w-id) you want to target.

2. Create a Custom JavaScript Snippet

  • Access your Webflow dashboard and open the project settings.
  • Navigate to the Custom Code section.
  • Add the following JavaScript snippet in the Footer Code area:

  ```javascript

  $(document).ready(function() {

    // Specify the data-w-id of the element

    var dataWID = 'your-data-w-id-value-here';

  

    // Start the interaction using Webflow's built-in methods

    Webflow.require('ix2').init({

      events: {

        [dataWID]: {

          id: dataWID,

          action: {

            actionTypeId: 'GENERALSTARTACTION',

            config: {

              delay: 0,

              easing: '',

              duration: 0

            }

          }

        }

      }

    });

    Webflow.destroy(); // Ensure no multiple instance interference

  });

  ```

  • Replace 'your-data-w-id-value-here' with the actual value of the data-w-id.

3. Test the Interaction

  • Publish your site to apply the new settings.
  • Visit the published page to see if the interaction launches as expected.

Summary

To trigger Webflow interactions using JavaScript, identify the element with the specific data-w-id, then use the built-in Webflow methods in a custom JavaScript snippet. Ensure to test the interaction by browsing the published site.

Rate this answer

Other Webflow Questions