I have a script that gets a table row from an ajax post and needs to append it to a table. Im wondering if there is away to turn the plain html that is returned into an object. Heres a simplified example
Expand|Select|Wrap|Line Numbers
- ajaxResult = "<tr><td>test</td></tr>";
- objTable = document.getElementById("mytable");
- newTR = turnHTMLintoObject(ajaxResult);
- objTable.appendChild(newTR);
I thought of a couple of easy work arounds:
1. I could return just the "<td>test</td>" bit then insert that into a new TR object with newTR.innerHTML = "<td>test</td>";
this means more code to set the attributes of the <tr> tag which would have been set by the php backend.
2. I could append the row to the table like so
objTable.innerHTML += ajaxResult;
But im wondering if there is away to turn the html directly into an object, which would be more helpful for other things i may want to do with the code before appending.
Thanks in advance!
Andy