Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a DOM Element from HTML

 
Onkar Joshi
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You apparently already know about innerHTML; why the acrobatics?
 
Onkar Joshi
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not just manipulate it in place?
 
Onkar Joshi
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic