Reputation: 4417
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
Upvotes: 1
Views: 139
Reputation: 27765
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') );
Upvotes: 2