While most updates you want to make to your page can be made using Mutiny's built in editor functionality, there may be instance where you want to apply Javascript to an experience.
Element-level custom Javascript is similar to page-level custom Javascript but it differs in that element-level custom Javascript is always tied to a specific element, making it impervious to some of the flicker issues that may exist with page-level Javascript.
Element-level custom Javascript will run as soon as the element is rendered.
Adding element-level custom Javascript
Element-level custom Javascript can be added to page content experiences.
- Navigate to the editor for the experience you'd like to add Javascript to.
- Select the element that you'd like to apply Javascript to.
- Select the "</>" icon on the right hand side, and select the element selector under "Element".
- You can write your Javascript in the box on the right. When you're finished, click "Apply" or "Discard unsaved changes".
- If Mutiny detects an error in your Javascript, we'll display a warning at the bottom. Note that you'll still be able to launch an experience if an error exists, so we recommend thoroughly testing your code before launching.
Additional parameters
Element-level custom Javascript allows for two additional parameters that you can utilize in your code:
-
element
: refers to the personalized element itself. -
hasRunBefore
: refers to a boolean value. It tells you whether or not your script has already run.
Comments
0 comments
Please sign in to leave a comment.