UNPKG

542 BJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.default = attribute;
5
6/**
7 * Gets or sets an attribute of a given element.
8 *
9 * @param node the element
10 * @param attr the attribute to get or set
11 * @param val the attribute value
12 */
13function attribute(node, attr, val) {
14 if (node) {
15 if (typeof val === 'undefined') {
16 return node.getAttribute(attr);
17 }
18
19 if (!val && val !== '') {
20 node.removeAttribute(attr);
21 } else {
22 node.setAttribute(attr, String(val));
23 }
24 }
25}
26
27module.exports = exports["default"];
\No newline at end of file