BoundForGlory
BoundForGlory

Reputation: 4417

Add custom attribute without a value jQuery

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

Answers (1)

antyrat
antyrat

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

Related Questions