Primary Use Cases for Dynamic Color Changes
- โInteractive Highlights
Focus learner attention on key terms, keypoints, or definitions when a user clicks a button.
- โInstant Knowledge Feedback
Change text box backgrounds to green or red based on user selection or assessment answers.
Step-by-step Configuration Guide
-
01
Assign an Accessibility Identifier
- Insert a text box onto your slide canvas.
- Right-click the text box and select Accessibility (or open the Alt Text properties).
- Ensure the alternative text checkbox is marked and enter text as the alternative text string.
- Close the panel. Storyline will render this value as the
data-acc-textattribute in the HTML5 DOM.
-
02
Configure the JavaScript Trigger
- Insert a shape or button component to serve as the trigger object.
- Open the Triggers panel and select Create a new trigger.
- Set the action parameters - Action: Execute JavaScript, When: User clicks, Object: Button or shape name.
- Click the JavaScript link in the Trigger Wizard to open the code editor.
-
03
Option A: Change Both Background Fill and Text Color
Paste the following code in the JavaScript Editor panel:
const texts = document.querySelectorAll('[data-acc-text="text"]'); texts.forEach(text => { text.style.backgroundColor = '#175FAD'; // Sets text box background color const txt = text.querySelector('text'); if (txt) { txt.style.fill = '#ffffff'; // Sets font fill color } });
-
04
Option B: Change Text Color Only
Paste the following code in the JavaScript Editor panel:
const texts = document.querySelectorAll('[data-acc-text="text"]'); texts.forEach(text => { const txt = text.querySelector('text'); if (txt) { txt.style.fill = '#C0504D'; // Sets font fill color } });
-
05
Test in Published Preview
Save your trigger setup and launch Preview or publish the project to HTML5 to test the interactive color transformation upon clicking the target button.
DOM Selector Explanation
| Script Function | Technical Description |
|---|---|
querySelectorAll('[data-acc-text="text"]') |
Scans the browser DOM for all elements matching the designated Accessibility text string (text). |
text.style.backgroundColor |
Alters the CSS background color property of the outer container box. |
txt.style.fill |
Alters the SVG fill color property of the child text node inside the Storyline element wrapper. |
Frequently Asked Questions
Why do we use Accessibility Alt Text to target elements in Storyline 360?
Storyline generates dynamic IDs for canvas elements upon publishing. Assigning a unique Accessibility Alt Text generates a predictable data-acc-text attribute that JavaScript can easily query.
Does this JavaScript technique work on mobile web browsers?
Yes. The script targets standard HTML5 DOM and SVG properties supported across modern desktop and mobile browsers.
Can I target multiple text boxes using the same script?
Yes. The querySelectorAll function loops through every text box sharing the specified accessibility text value and applies the style change simultaneously.