[Project_owners] How to insert text as HTML?

Eric Jung grimholtz at yahoo.com
Tue Aug 30 17:34:33 EDT 2005


If the "Here's a better test" text node doesn't already exist, you
don't have to remove it.


--- Michael Nachbaur <mike at nachbaur.com> wrote:

> Michael Vincent wrote:
> > Eric Jung wrote:
> > 
> >> Use the DOM Core Level 1 API
> >>
>
http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html
> >>
> >> var myDiv = document.getElementById("mydiv");
> >> var link = document.createElement("a");
> >> var linkText = document.createTextNode("MultiZilla");
> >> link .setAttribute("href", "http://multizilla.mozdev.org/");
> >> link .appendChild(linkText);
> >> myDiv.appendChild(link);
> > 
> > 
> > Thanks Eric, but I'm afraid that my HTML example snippet was not
> clear 
> > enough because what I need really is to insert that link inside a
> <p> 
> > element, at a given position. Lets take this example:
> > 
> > <p>Here's a better test</p>
> > 
> > and the text 'better' should become my link, so how does that
> work?
> 
> 
> You'll need to remove the text node that is the child of the "p"
> tag, 
> and create two new text nodes:  one for the text "Here's a ", and
> the 
> second for " test".  I have some code lying around somewhere that
> does 
> this, but I just got back from vacation and have no clue where I
> put 
> anything.  This might get you on the right track though:
> 
> http://xulplanet.com/references/objref/Text.html#method_splitText
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 



		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 


More information about the Project_owners mailing list