Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33420

Re: inner outer html and appendchild

Subject Re: inner outer html and appendchild
Newsgroups comp.lang.javascript
References <4N-dnWxtPtO7I7bEnZ2dnUU7-KPNnZ2d@westnet.com.au> <oggpj2$tsj$1@news.albasani.net>
From Andrew Poulos <ap_prog@hotmail.com>
Date 2017-05-29 20:21 +1000
Message-ID <id6dnY5WDoqya7bEnZ2dnUU7-afNnZ2d@westnet.com.au> (permalink)

Show all headers | View raw


On 29/05/2017 7:28 PM, Martin Honnen wrote:
> On 29.05.2017 08:22, Andrew Poulos wrote:
>> I know about the differences between innerHTML and appendChild but I'm 
>> in a bit of a bind. If the uses passes a valid html element as a 
>> string how do I add it to the document without needing to parse the 
>> sting or contain it in a DIV?
>>
>> For example, the users passes (the dots are for brevity)
>>    str = "<img id='.' src='..jpg' alt='.' style='.' >";
>> or
>>    str = "<div id='.' style='.'><p id='.' style='.'>Text <span 
>> style='.'></span></p></div";
>>
>> Ideally I'd like to do something like
>>    document.body.appendChild(str);
> 
> Use
>    document.body.insertAdjacentHTML('beforeEnd', str)

Thanks.

> https://www.w3.org/TR/DOM-Parsing/#widl-Element-insertAdjacentHTML-void-DOMString-position-DOMString-text 
> and http://caniuse.com/#search=insertAdjacentHTML suggests it is usable

MDN suggests it's supported by IE as far back as version 4.

Andrew Poulos

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

inner outer html and appendchild Andrew Poulos <ap_prog@hotmail.com> - 2017-05-29 16:22 +1000
  Re: inner outer html and appendchild Julio Di Egidio <julio@diegidio.name> - 2017-05-29 01:30 -0700
  Re: inner outer html and appendchild Martin Honnen <martin.honnen@gmx.de> - 2017-05-29 11:28 +0200
    Re: inner outer html and appendchild Andrew Poulos <ap_prog@hotmail.com> - 2017-05-29 20:21 +1000
      Re: inner outer html and appendchild Martin Honnen <martin.honnen@gmx.de> - 2017-05-29 12:25 +0200
  Re: inner outer html and appendchild Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-29 19:04 +0200
    Re: inner outer html and appendchild Julio Di Egidio <julio@diegidio.name> - 2017-05-29 10:20 -0700
      Re: inner outer html and appendchild Andrew Poulos <ap_prog@hotmail.com> - 2017-05-30 07:40 +1000
        Re: inner outer html and appendchild Julio Di Egidio <julio@diegidio.name> - 2017-05-29 22:32 -0700
          Re: inner outer html and appendchild Andrew Poulos <ap_prog@hotmail.com> - 2017-05-30 17:29 +1000
            Re: inner outer html and appendchild Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-05-30 13:13 +0200
              Re: inner outer html and appendchild Tim Streater <timstreater@greenbee.net> - 2017-05-30 12:34 +0100
            Re: inner outer html and appendchild Julio Di Egidio <julio@diegidio.name> - 2017-05-30 05:28 -0700

csiph-web