| View previous topic :: View next topic |
| Author |
Message |
kadamat
Joined: 01 Jun 2006 Posts: 88
|
| How do I make '<p>' str to be evaluated as html tag ? |
| |
|
|
|
|
Peter Pitt
Joined: 20 May 2006 Posts: 114 Location: Egypt
|
| document.createElement('p') |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
i do:
Var txt = document.createTextNode(str);
Comments.appendChild(txt); |
| |
|
|
Peter Pitt
Joined: 20 May 2006 Posts: 114 Location: Egypt
|
| that's a textnode, I meant document.createElement() |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
Should I create all markup as elements ?
My 'str' lookadamat like '<p> aaa <b>mmm</b>' |
| |
|
|
Peter Pitt
Joined: 20 May 2006 Posts: 114 Location: Egypt
|
then instead, use .innerHTML
Comments.innerHTML=str; |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
| that's not working for me in IE |
| |
|
|
Peter Pitt
Joined: 20 May 2006 Posts: 114 Location: Egypt
|
It should
Depending on what 'comments' may be |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
| It's <div> |
| |
|
|
Roombor
Joined: 02 Jun 2006 Posts: 111
|
| You should indeed create all markup as elements. The DOM is the way forward. :) |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
Roombor, will it work if add it later to var txt = document.createTextNode(str); ?
I mean is it valid to add object as input for TextNode ? |
| |
|
|
|
|
Roombor
Joined: 02 Jun 2006 Posts: 111
|
kadamat, I'm not sure what you mean.
A text node is just something which contains a bunch of text. So the argument for createTextNode is always a string.
If you want to create all sorts of complicated formatting for your string I will grudgingly admit that innerHTML might be better. For example document.addTextNode('This text is <strong>bold</strong>') shouldn't work. |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
| Thankadamat for help |
| |
|
|
|