Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery wrapping poorly formatted HTML
    primarykey
    data
    text
    <p>I have some extremely poorly formatted HTML code, where each element in a table is a row. I want to group the sub-elements a little easier, by adding some HTML to the page. Here is a small example of the HTML:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;table width="100%"&gt; &lt;tr class="heading"&gt; &lt;td&gt;value 1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 1&lt;/td&gt; &lt;/tr&gt; &lt;tr class="heading"&gt; &lt;td&gt;value 2&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 2&lt;/td&gt; &lt;/tr&gt; &lt;tr class="heading"&gt; &lt;td&gt;value 3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 3&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;​ </code></pre> <p>I'd like to wrap each of the rows with a class of heading, with another tr or div or really anything to allow me to grab the sub-elements a bit easier. I've tried various combinations of before, html, etc.. yet I can't seem to get this to work.</p> <p>Here is a <a href="http://jsfiddle.net/XPNFf/" rel="nofollow">jsfiddle</a> that I've put together. Any way to wrap the the tr values with a class of heading? For example, I'd like to grab the 3 rows with class heading in the sample HTML. I'd like to prepend that first row with some HTML, and close it before the start of the second row. I would repeat that process for each row (open a tag and close it before the next row), on the final row I would simply close it.</p> <p>So the output I would like is:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;table width="100%"&gt; &lt;SOME_TAG&gt; &lt;tr class="heading"&gt; &lt;td&gt;value 1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 1&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 1&lt;/td&gt; &lt;/tr&gt; &lt;/SOME_TAG&gt; &lt;SOME_TAG&gt; &lt;tr class="heading"&gt; &lt;td&gt;value 2&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 2&lt;/td&gt; &lt;/tr&gt; &lt;/SOME_TAG&gt; &lt;SOME_TAG&gt; &lt;tr class="heading"&gt; &lt;td&gt;value 3&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;sub 3&lt;/td&gt; &lt;/tr&gt; &lt;/SOME_TAG&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt;​ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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