🚧elem.showDataAttr()

show element's "data-xxx" attribute compared with its `dataset` property.

🔰 JSDOMTypesElement

// ⭐️ elem.showDataAttr('data-xxx')
//    show element's "data-xxx" attribute & property
Element.prototype.showDataAttr = function (dataAttr){
  const prop = dataAttr.toDatasetPropName();
  log(`${this.nodeName.toLowerCase()}.${prop} = '${this.dataset[prop]}'`);
  log(`${dataAttr}='${this.attr(dataAttr)}'`);
}

// sample result:
// -----------------------
// div.widgetName = 'menu'
// data-widget-name='menu'

Last updated