Table of Contents
- “Hooks” and Element Selections
- “Sensing” Events
- Hiding and showing elements
“Hooks” and Element Selections
Coming from Harlowe, the following code may seem the strangest. However, like in how SugarCube understands element selections, many jQuery functions work from selectors. Through finding one or more elements, effects and attributes can be applied or changed on some element or elements much in the same way Harlowe works on named hooks.
In fact, following a common trend of placing sensor macros at the bottom of a passage in Harlowe, we can write code that looks much like how macros work in SugarCube, but are based in using jQuery and <script> tags instead.
Changing the text-color (color) of an element
Replacing the text of some element
In Harlowe, there are Sensor Macros. These are macros that “sense” events like clicks and mouseover events. In SugarCube, there are also Interactive Macros like <<button>> and <<click>> that react to something a user does.
Using jQuery, we can replicate some of that behavior by using the Events functionality to listen and act on different behaviors.
Hiding and showing elements
Both Harlowe and SugarCube have functionality to create “temporary content”: links and hooks that, when clicked, disappear. To do this effect in jQuery requires some extra code to ‘catch’ an event and then apply a function to hide() or show() it.