[Project_owners] How to insert text as HTML?

Michael Vincent mv_van_rantwijk at yahoo.com
Tue Aug 30 02:18:17 EDT 2005


Konstantin Svist wrote:
> How about
> 
> var myHTMLsource = '<a href="...">blah</a>';
> var myDiv = document.getElementById("mydiv");
> myDiv.innerHTML = myHTMLsource;

Ah, innerHTML must be it. Let me give that a try, to see how it works, 
Thanks guys!

Michael

> On 8/29/05, Michael Vincent <mv_van_rantwijk at yahoo.com> 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);
>> The problem is that it can be just about any HTML element, nested or
>> not, so this won't work for me. Thanks any way.
>>
>>> --- Michael Vincent <mv_van_rantwijk at yahoo.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I have a string with HTML code that I need to insert in a HTML
>>>> document,
>>>> inside a <div> element, but how should that be done?
>>>>
>>>> Lets take this example:
>>>>
>>>> "<a href="..">my link</a>"
>>>>
>>>> That should be inserted, as HTML, in a <div> element and it should
>>>> be
>>>> HTML i.e. a true link, not the above text!
>>>>
>>>> Thanks for your help/tips,
>>>> Michael


More information about the Project_owners mailing list