- h
- .getAttrs(prefix, [node]) ⇒
function
|object
- .getChildrenWithData(parentNode, dataKey, [dataValue]) ⇒
NodeList
- .getAttrs(prefix, [node]) ⇒
Get all prefixed data-
attributes as an object
Kind: static method of h
Returns: function
| object
- - curried function for parsing node with passed prefix or parsed attrs
Param | Type | Description |
---|---|---|
prefix | string |
data- attribute prefix |
[node] | HTMLNode |
target node |
Example
// <div id="n" data-x-a="lol" data-x-b="1" data-y-c='{"key": 1}' data-y-composed-attr="true"></div>
Baz.h.getAttrs('x', window.n) // => {a: "lol", b: 1}
Baz.h.getAttrs('y', window.n) // => {y: {key: 1}, composedAttr: true}
const xAttrs = Baz.h.getAttrs('x')
xAttrs(window.n) // => {x: "lol", b: 1}
Query children with specific data-
attribute
Kind: static method of h
Param | Type | Description |
---|---|---|
parentNode | HTMLNode |
|
dataKey | string |
– data-key. data-baz-key , baz-key and bazKey are equivalent |
[dataValue] | string |
value of a data- attribute |
Example
// <div id="parent">
// <div data-user-id="1">yep</div>
// <div data-user-id="2">nope</div>
// </div>
Baz.h.getChildrenWithData(window.parent, 'data-user-id', 1)[0].textContent === 'yep'
Baz.h.getChildrenWithData(window.parent, 'user-id', 1)[0].textContent === 'yep'
Baz.h.getChildrenWithData(window.parent, 'userId', 2)[0].textContent === 'nope'