I have a function that gets raw HTML to output to a table, but I want to take out the first three columns and put them in another div.
I am considering making a div on the page that is hidden, setting this div’s html to the raw HTML I get, and then using the selector syntax to strip it into each table’s div. Is there a way to do this without the intermediate faux-div to hold the raw HTML?
I’m not sure exactly why you’d want to do this, rather than arrange your data server-side, but one approach that works is:
With the (x)html:
JS Fiddle demo
The demo uses jQuery’s
click()event, but that’s just to show it working interactively; it could certainly be placed straight into the DOM-ready/$(document).ready(function(){/* ... */});event.The above code would allow repeated clicks (each time moving the first ‘column’ into a new table), the edit removes that possibility using jQuery’s
one(), giving the following jQuery:JS Fiddle demo, featuring
one().