0

I am making a google extension that shows a div overlay. However, on the inner div, the second h1 (Small Label) is not showing up. Here is the code:

chrome.runtime.onMessage.addListener((request,sender,sendMessage)=>{
      //defined and styled other div
      //div within the div
      var labelBackground = document.createElement('div');
      labelBackground.width = '20rem';
      labelBackground.height = '10rem';
      labelBackground.style.display = 'flex';
      labelBackground.style.flexDirection = 'column';
      labelBackground.style.position = 'absolute';
      labelBackground.style.top = '25%';
      labelBackground.style.left = '60%';

      var label = document.createElement('h1');
      label.innerHTML = "Text one"; //showing properly
      label.style.color = 'white';
      label.style.fontSize = '4rem';
      label.style.textAlign = 'center';

      var smallLabel = document.createElement('h1');
      smallLabel.innerHTML = "Text 2"; //not showing properly
      smallLabel.style.fontSize = '1.5rem';
      smallLabel.style.marginBottom = '1rem';

    //Description
      var description = document.createElement('p');
      smallLabel.innerHTML = "Text 3";

      labelBackground.appendChild(label);
      labelBackground.appendChild(smallLabel);
      labelBackground.appendChild(description);
      div.appendChild(labelBackground);
      document.body.appendChild(div);
      sendMessage({msg:'recieved'})
})
Angelina Tsuboi
  • 196
  • 1
  • 2
  • 14
  • 1
    1) `smallLabel.innerHTML` is assigned twice, 2) page may apply its CSS to your elements, see [How to really isolate stylesheets in the Google Chrome extension?](https://stackoverflow.com/q/12783217) – wOxxOm Jun 23 '20 at 17:12
  • @wOxxOm Awesome! It works now. Thank you. – Angelina Tsuboi Jun 23 '20 at 21:11

0 Answers0