Rebuild each definition list () as a table using JQuery -



Rebuild each definition list (<dl>) as a table using JQuery -

i having want convert table format help of jquery. please reply

html: current

<div id="item"> <dl> <dd>a</dd> <dt>b</dt> <dd>c</dd> <dt>d</dt> <dd>e</dd> <dt>f</dt> </dl> </div>

html desired

<table> <tr> <td>a</td> <td>b</td> </tr> <tr> <td>c</td> <td>d</td> </tr> <tr> <td>e</td> <td>f</td> </tr> </table>

class="snippet-code-js lang-js prettyprint-override">$(document).ready(function() { var table = $('<table/>'), tbody = $('<tbody/>'), tr = $('<tr/>'), tds = $('#item').find('dd,dt').clone(), thistr = tr.clone(); $.each( tds, function(i) { thistr.append( $('<td/>').text( $(this).text() ) ); if( % 2 === 1 ) { table.append( thistr ); thistr = tr.clone(); } }); $('#item').html( table ); }); class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="item"> <dl> <dd>a</dd> <dt>b</dt> <dd>c</dd> <dt>d</dt> <dd>e</dd> <dt>f</dt> </dl> </div>

jquery table

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -