Is it possible in any way when issuing information to id1 block to output information to another id2 block via js code in string1?

<html> <head> <script> var string2='string2'; // var string1='<scri' +'pt>document. getElementById("id2").HTML=string2;</scri'+ 'pt>'; // не работает var string1='document. getElementById("id2").innerHTML=string2'; // работает function f() { document.getElementById('id1').innerHTML=string1; } </script> </head> <body> <div id="id1"> </div> <div id="id2"> </div> <input type=button value='Press' onClick='f()'> </body> </html> 

But is this option (only correct) possible?

  document.getElementById('id1').innerHTML='Содержимое для id1 <scri' +'pt>document. getElementById("id2").innerHTML="Содержимое для id2";</scri'+ 'pt>'; 

Those. with one command, when issuing to id1, both the id1 block and the other id2 block change.

    1 answer 1

    Via DOM:

     function f() { var scr = document.createElement( "script" ); scr.textContent = string1; documend.head.appendChild( scr ); }; 

    Via eval:

     function f() { eval( string1 ); }; 
    • via new Function() : new Function (string) .call (this); - lampa