_hyperscript icon indicating copy to clipboard operation
_hyperscript copied to clipboard

"If" functionality which remove/add element from the DOM

Open matndev opened this issue 2 years ago • 0 comments

I would like to replicate the ngIf directive from Angular in hyperscript.

To do that I need to remove or add from DOM elements based on a condition.

But I didn't find a manner with hyperscript currently.

Here an example code to begin with :

<div _="set global currentItem to 0">

        <div **for loop with index **>
            <div class="element**index**"">
                <p>Hello world</p>
            </div>
        </div>

        <button _="on click show :currentItem and remove others then halt the event">
</div>

The idea is to hide/show (by removing or adding) element depending its index. If the index is equal tu currentItem it shows the element otherwise it is removing it.

matndev avatar Dec 20 '23 17:12 matndev