0

What are the benefits or cost of doing this:

document.getElementById('asd').myData=123

then document.getElementById('asd').myData; //123

vs

document.getElementById('asd').setAttribute('data-item',123);
document.getElementById('asd').getAttribute('data-item'); //123

Also where is data exactly being stored when i attach it dom element as variable.

Muhammad Umer
  • 17,263
  • 19
  • 97
  • 168
  • @Paul S Linked question's answer no where tell: The difference in these two, or how attaching variables to dom works. The answer just says "You should always use attribute" – Muhammad Umer May 24 '15 at 14:12
  • 1
    There are many other duplicates also; [here](https://stackoverflow.com/questions/11886820/what-is-the-difference-between-setattribute-and-dot-notation-in-javascript), [here](https://stackoverflow.com/questions/22151560/what-is-happening-behind-setattribute-vs-attribute), [here](https://stackoverflow.com/questions/8018814/setting-a-property-via-property-or-setattribute) etc. – dsgriffin May 24 '15 at 14:15

0 Answers0