Reputation: 1065
I'm trying to add a custom property to an existing element by I find it impossible.
There's a Map of attributes to my element but there's not properties Map.
I tried doing something like this:
el.someProperty = 'Some value';
but this line produced an error that el does not have get$someProperty.
I would like to do something similar to jQuery that you can just use
el.prop('propName', 'value');
Thanks.
Upvotes: 1
Views: 821
Reputation: 657288
Use
el.attributes['someProperty'] = 'Some value';
if that doesn't work use
el.dataset['someProperty'] = 'Some value';
this way the added attribute will get a data
prefix and probably named data-some-property
(haven't tested)
Upvotes: 3