-3

This code make an error. Probably the problem is with location.href apostrophes.

div.innerHTML ='<div id="link">\
<input type="button" onclick="location.href='http://www.google.com';"/>\
</div>';
Prova Allwinner
  • 117
  • 1
  • 1
  • 6
  • @Pablo No, that's not a dupe. The linked question is about bash, which uses a completely different escape mechanism to JavaScript. – melpomene Feb 24 '17 at 15:06

1 Answers1

1

You can escape your string like this:

div.innerHTML ='<div id="link">\<input type="button" onclick="location.href=\'http://www.google.com/\';"/>\</div>';
Esdes
  • 984
  • 7
  • 12