How do i add custom attribute without a value jQuery? I want the following:
<tr data-header-row>
The following does not work:
$(tr).prop('data-header-row',true);
Thanks
To add HTML element attributes in jQuery you need to use attr method:
$(tr).attr('data-header-row','true');
But I would suggest you to use data method instead:
$(tr).data('header-row', true);
It will automatically add data- namespace to your attribute.
To get stored value then you can do simple:
console.log( $(tr).data('header-row') );
.data() does not actually add an attribute, just saves the value and links it to the element in a jQuery internal cache.data you can grab attributes values without adding an preffix.$(tr).attr('data-header-row','');