Ask Your Question
0

How to add a tr with full table width to an existing table using DHTML?

asked 2022-08-02 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-11-04 20:00:00 +0000

woof gravatar image

To add a tr (table row) with full table width to an existing table using DHTML, you can use the following approach:

  1. Retrieve the table element using JavaScript or jQuery.

  2. Create a new tr element and set its width to 100% of the table using inline CSS or a class.

  3. Insert the new tr element into the table's tbody or thead section, depending on where you want it to appear.

Here is an example code using vanilla JavaScript:

// Retrieve the table element
const table = document.getElementById('myTable');

// Create a new tr element with full table width
const newRow = document.createElement('tr');
newRow.style.width = '100%';

// Insert the new tr into the table body
const tableBody = table.getElementsByTagName('tbody')[0];
tableBody.appendChild(newRow);

And here's an example code using jQuery:

// Retrieve the table element using jQuery
const $table = $('#myTable');

// Create a new tr element with full table width
const $newRow = $('<tr>').css('width', '100%');

// Insert the new tr into the table body
$table.find('tbody').append($newRow);
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-02 11:00:00 +0000

Seen: 9 times

Last updated: Nov 04 '21