Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First you should not be using multiple ID's with the same value! You should use classes.</p> <p>Second of all, the below code works but you will need to change it to suit your application.</p> <p>If you don't want the contents copied just remove the html() call on each of the cells.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript" language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="test"&gt; &lt;tr id="row-1"&gt;&lt;td class="col-1"&gt;col 1&lt;/td&gt;&lt;td class="col-2"&gt;col 2&lt;/td&gt;&lt;td class="col-3"&gt;col 3&lt;/td&gt;&lt;/tr&gt; &lt;tr id="row-2"&gt;&lt;td class="col-1"&gt;col 1&lt;/td&gt;&lt;td class="col-2"&gt;col 2&lt;/td&gt;&lt;td class="col-3"&gt;col 3&lt;/td&gt;&lt;/tr&gt; &lt;tr id="row-3"&gt;&lt;td class="col-1"&gt;col 1&lt;/td&gt;&lt;td class="col-2"&gt;col 2&lt;/td&gt;&lt;td class="col-3"&gt;col 3&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;div id="mirror"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; var table = $('#test'); var OUTPUT = '&lt;table id="test"&gt;'; for (var i = 1; i &lt;= $('#test tr').length; i++){ OUTPUT += '&lt;tr id="row-' + i + '"&gt;'; OUTPUT += '&lt;td class="col-1"&gt;' + $('#row-' + i + " .col-3").html() + '&lt;/td&gt;' + "\n"; OUTPUT += '&lt;td class="col-2"&gt;' + $('#row-' + i + " .col-2").html() + '&lt;/td&gt;' + "\n"; OUTPUT += '&lt;td class="col-3"&gt;' + $('#row-' + i + " .col-1").html() + '&lt;/td&gt;' + "\n"; OUTPUT += '&lt;/tr&gt;'; }; OUTPUT += '&lt;/table&gt;'; $('#mirror').html(OUTPUT); &lt;/script&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload