Comment diviser une ligne de table avec jQuery (insérer TR entre TD)

J’ai un problème pour diviser une table avec jQuery.

Ceci est la table:

 

Je veux que cela ressemble à ceci après avoir appelé une fonction:

  

J’ai essayé avec:

 $(function(){ $('.submenu td:eq(3)').after(''); }); 

Essayez plutôt cet extrait:

 $(function(){ // # Add a new row after the first one in the table $('table#submenu tr:first').after(''); // # Move the four last TDs to this new row $('table#submenu tr:first td.submenu:gt(3)') // Select the four last TDs .detach() // Detach them from their current row .appendTo('table#submenu tr:nth-child(2)'); // Add them at the end of the new row }); 
   
  

Cela fonctionnera.

Ce code résout votre problème.

entrez la description de l'image ici

 $(document).ready(function(){ $("table tr td:nth-child(5n)").addClass('break'); var boundary = $("td.break"); $("").insertAfter(boundary.parent()).append(boundary.nextAll().andSelf()); }); 

DEMO