-1

I am trying to add div tag to body tag. Inside div tag I am using iframe. Here is my code:

<script>
  (function() {
    var div = document.createElement("div");
    document.getElementsByTagName('body')[0].appendChild(div);
    div.outerHTML = "<div id='botDiv' style='height: 38px; position: fixed; bottom: 0; z-index: 1000; background-color: #fff'><div id='botTitleBar' style='height: 38px; width: 400px; position:fixed; cursor: pointer;'></div><iframe width='400px' height='600px' src='https://SitePages/botchat.html'></iframe></div>";
    document.querySelector('body').addEventListener('click', function(e) {
      e.target.matches = e.target.matches || e.target.msMatchesSelector;
      if (e.target.matches('#botTitleBar')) {
        var botDiv = document.querySelector('#botDiv');
        botDiv.style.height = botDiv.style.height == '600px' ? '38px' : '600px';
      };
    });
  }());
</script>
barbsan
  • 3,418
  • 11
  • 21
  • 28
sandeep
  • 449
  • 2
  • 7
  • 22

1 Answers1

0

Use `` backticks for the string of outerHTML

(function() {
  var div = document.createElement("div");
  document.getElementsByTagName('body')[0].appendChild(div);
  div.outerHTML = `<div id='botDiv' style='height: 38px; position: fixed; bottom: 0; z-index: 1000; background-color: #fff'>
<div id='botTitleBar' style='height: 38px; width: 400px; position:fixed; cursor: pointer;'></div>
<iframe width='400px' height='600px' src='https://SitePages/botchat.html'></iframe></div>`;
  document.querySelector('body').addEventListener('click', function(e) {
    e.target.matches = e.target.matches || e.target.msMatchesSelector;
    if (e.target.matches('#botTitleBar')) {
      var botDiv = document.querySelector('#botDiv');
      botDiv.style.height = botDiv.style.height == '600px' ? '38px' : '600px';
    };
  });
}());
<body></body>
ellipsis
  • 12,049
  • 2
  • 17
  • 33