Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] document.createElement("TBODY")
- From: hassan at webtuitive.com (Hassan Schroeder)
- Subject: [Javascript] document.createElement("TBODY")
- Date: Tue Apr 17 10:36:42 2007
Michael Borchers wrote:
> Is there any other way to parse the response than innerHTML?
Using innerHTML is not "parsing" the response. At all. It's sticking
a lump of cr--, er, whatever, into your page, rather than explicitly
(and IMHO properly) inserting elements into the DOM.
For simplicity's sake, let's say this row is returned by an AJAX
request:
<tr><td>now</td><td>is</td><td>the</td><td>time</td></tr>
:: and you want to insert it into a tbody with the id "tb".
/* using Prototype */
function append(row)
{
var tr = document.createElement("tr");
$('tb').appendChild(tr);
var cells = row.firstChild.getElementsByTagName("td");
$A(cells).each( function(cell){
var text =
document.createTextNode(cell.firstChild.nodeValue);
var td = document.createElement("td");
td.appendChild(text);
tr.appendChild(td);
});
}
function fetch()
{
new Ajax.Request("/tr.jsp", {
onSuccess : function(transport){
append(transport.responseXML); },
onFailure : function(){ alert('failed'); }
});
}
At least, that's how I'd do it :-)
FWIW,
--
Hassan Schroeder ----------------------------- hassan@xxxxxxxxxxxxxx
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
opinion: webtuitive.blogspot.com
dream. code.
- Follow-Ups:
- [Javascript] document.createElement("TBODY")
- From: Nick Fitzsimons
- [Javascript] document.createElement("TBODY")
- From: Scott Reynen
- [Javascript] document.createElement("TBODY")
- From: Paul Novitski
- [Javascript] document.createElement("TBODY")
- From: Michael Borchers
- [Javascript] document.createElement("TBODY")
- References:
- [Javascript] document.createElement("TBODY")
- From: Michael Borchers
- [Javascript] document.createElement("TBODY")
- From: Hassan Schroeder
- [Javascript] document.createElement("TBODY")
- From: Michael Borchers
- [Javascript] document.createElement("TBODY")
- From: Hassan Schroeder
- [Javascript] document.createElement("TBODY")
- From: Michael Borchers
- [Javascript] document.createElement("TBODY")
- Prev by Date: [Javascript] document.createElement("TBODY")
- Next by Date: [Javascript] document.createElement("TBODY")
- Previous by thread: [Javascript] document.createElement("TBODY")
- Next by thread: [Javascript] document.createElement("TBODY")
- Index(es):