Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Update a count state value with the x-on event listener directive in Alpine JS


    In this lesson, we define a "count" state value with the x-data directive provided by Alpine JS. This defines a new scoped component, which can have access to this state.

    We then display the "count" value in our HTML with the x-text directive, which updates an element's innerText value.

    We also hook up buttons with click event listeners with x-on:click, which allows us to modify the count value as desired.