MCPcopy Index your code
hub / github.com/processing/p5.js / attribute

Method attribute

src/dom/p5.Element.js:1235–1256  ·  view source on GitHub ↗

* @param {String} attr attribute to set. * @param {String} value value to assign to the attribute. * @chainable

(attr, value)

Source from the content-addressed store, hash-verified

1233 * @chainable
1234 */
1235 attribute(attr, value) {
1236 //handling for checkboxes and radios to ensure options get
1237 //attributes not divs
1238 if (
1239 this.elt.firstChild != null &&
1240 (this.elt.firstChild.type === 'checkbox' ||
1241 this.elt.firstChild.type === 'radio')
1242 ) {
1243 if (typeof value === 'undefined') {
1244 return this.elt.firstChild.getAttribute(attr);
1245 } else {
1246 for (let i = 0; i < this.elt.childNodes.length; i++) {
1247 this.elt.childNodes[i].setAttribute(attr, value);
1248 }
1249 }
1250 } else if (typeof value === 'undefined') {
1251 return this.elt.getAttribute(attr);
1252 } else {
1253 this.elt.setAttribute(attr, value);
1254 return this;
1255 }
1256 }
1257
1258 /**
1259 * Removes an attribute from the element.

Callers 1

p5.Element.jsFile · 0.80

Calls 1

setAttributeMethod · 0.80

Tested by

no test coverage detected