• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

document.createTextNode But Need To Render a href

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an array of data. Each array element will be data for a TD in a table. I am using the DOM to create my TBODY with all the rows and data. The problem is that the first elements in the array is actually a string of text containing a link. So it looks like

"<a href='fjdkslfjklsd'>view</a>"

The problem is that using document.createTextNode and passing in that value it is just displaying plain text. The next problem is that simply using document.createElement("A") and creating the link that way won't work because I can't always be sure that the link will appear as the first element in the array as I am not the only one using this function. Does anyone know what I might be able to do to solve my issues?

Thanks.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you've already got pre-formatted HTML, use innerHTML rather than DOM manipulation.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
If you've already got pre-formatted HTML, use innerHTML rather than DOM manipulation.



Well, that's the problem. For some reason I am having issues with IE an innerHTML when I try and add text to the tbody of a table. I can some obscure "runtime error". Firefox works great. So I switched to this method to see if I could solve the problem this way, and then of course ran into other problems.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not sure if this even works, never tried it, but popped into my head.

will a try catch stament catch IE's problem with innerHTML? If so maybe this would work, (Have no clue)



or maybe object detection



Wish I had a real solution other then saying, redeisgn the strings to use createElements!!

Eric
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH MAN!!!

My last sentence turned on a lightbulb.....

IE does allow this, FF/Moz does not

var eHTML = document.createElement("<a href='blah'>asdf</a>");

so you may be able to do this if you can catch that error like I mentioned above.

Eric
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions. But I guess what I really want to know is why can't IE do this...





Firefox does it. But IE gives that 'unknown runtime error'.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:
what I really want to know is why can't IE do this...



Do you really need the obvious answer?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


Do you really need the obvious answer?





Well, after much trial and error I finally got something to work. I had to use insertRow and insertCell so I had to completely change my function. Better or worse? Who cares, it works. I am tired of javascript!!!
reply
    Bookmark Topic Watch Topic
  • New Topic