I\'m trying to use the code below to dynamically add closing tag followed by opening so that i creates a new row every three cells. Almost working, DOM inspector shows a T
You can't work on a DOM selection as if it was an HTML document. A DOM document is a hierarchy of nodes, not of tags. The tags in your HTML are parsed into a DOM document by the browser. You can't then add a single bit of HTML and then expect it to be parsed back into a DOM structure.
Instead, you'll need to do the wrapping in jQuery. This is a viable approach -- it may not be the most efficient.
$('td').each(function(idx) {
if (idx % 3) {
return;
} else {
$(this).nextAll(':lt(2)').andSelf().wrapAll(' ');
}
}).parent().unwrap();
jsFiddle