1

I am trying to add a Bootstrap Table table tag with Javascript. One of the parameters for the table tag is data-pagination. This method of adding it, is failing due to the -.

How can I work around this?

Desired Output:

<table id="mytable" data-pagination="true" class="table table-striped"></table>

My code:

var table_div = document.createElement('table');
table_div.id = 'mytable';
table_div.className = "table table-striped";
table_div.data-pagination = "true";
document.body.appendChild(table_div);
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
user2242044
  • 8,803
  • 25
  • 97
  • 164

2 Answers2

2

You could use the dataset in this case like :

table_div.dataset.pagination = true;

Hope this helps.

var table_div = document.createElement('table');
table_div.id = 'mytable';
table_div.className = "table table-striped";
table_div.dataset.pagination = "true";
document.body.appendChild(table_div);

console.log(document.body.innerHTML)
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
1

table_div.setAttribute('data-pagination', 'true')

Kostas
  • 1,903
  • 1
  • 16
  • 22