How to find array of properties by data attribute JavaScript – best methods? or What’s the easiest wa

16 Replies, 1610 Views

Yo! If speed matters, `getAttribute` can sometimes be faster than `dataset` for simple checks.

For your case:
```javascript
const adminElements = Array.from(document.querySelectorAll('[data-role="admin"]'));
```

Boom, done. No extra filtering needed.

Messages In This Thread



Users browsing this thread: 1 Guest(s)