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


Groups > comp.lang.javascript > #33419

Re: inner outer html and appendchild

From Martin Honnen <martin.honnen@gmx.de>
Newsgroups comp.lang.javascript
Subject Re: inner outer html and appendchild
Date 2017-05-29 11:28 +0200
Organization Liberty Development
Message-ID <oggpj2$tsj$1@news.albasani.net> (permalink)
References <4N-dnWxtPtO7I7bEnZ2dnUU7-KPNnZ2d@westnet.com.au>

Show all headers | View raw


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)

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

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