| Author |
Creating a DOM Element from HTML
|
Onkar Joshi
Ranch Hand
Joined: Mar 01, 2007
Posts: 116
|
|
I do an Ajax call and get HTML (a table row, tr). Now I can stuff this into a table as well. But I'm doing some acrobatics for that. I stuff it into a invisible div first. Then get the row by element id. Then insert the row element else where.
Is there a cleaner way to convert text received from an Ajax call into a DOM element?
|
SCJP 5 - 95% | SCWCD 1.4 - 88% | SCBCD 5 - 93%
Onkar Joshi's blog | LinkedIn profile
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56547
|
|
|
You apparently already know about innerHTML; why the acrobatics?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Onkar Joshi
Ranch Hand
Joined: Mar 01, 2007
Posts: 116
|
|
Because I want to do some DOM manipulations on the text received from the Ajax call.
I looked around a bit. Perhaps this might be what I'm looking for : http://www.w3schools.com/Xml/xml_parser.asp
BTW, Bear, I started on your jQuery book the day before! Lovely stuff. I am clearly writing too much code at present. Won't be so when I'm done with your book. :-)
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56547
|
|
|
Why not just manipulate it in place?
|
 |
Onkar Joshi
Ranch Hand
Joined: Mar 01, 2007
Posts: 116
|
|
Because I already had an element(row) with the same id in the document. (It is a dynamically add row/remove row) kind of thing. So before adding it to the dom, I wanted to remove its id. The row id is the same because initially a jsp is included for a single row and later the same jsp is retrieved via ajax.
Anyway, I removed the initial rows id attribute in onLoad. So now I can do the inplace thing. Infact I might not need the id in the first place...but there are other things being loaded in the row too...gotta look into that.
But still, I'd like to know what's the best way to get a DOM element out of text?
|
 |
 |
|
|
subject: Creating a DOM Element from HTML
|
|
|