Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Creating a DOM Element from HTML

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 67497
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You apparently already know about innerHTML; why the acrobatics?
 
Oscar Johansson
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 67497
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not just manipulate it in place?
 
Oscar Johansson
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic