JS learning of the day

So today i am working on click2contact.app its a chat widget, So i have added option in the website to update the widget and get the code

Problem: I need to set styling on selection from drop down

here is how i did it first, DID NOT WORKED

   document.getElementById("divContainer").style.position = "fixed";
      document.getElementById("openButton").style.position = "fixed";

this DID WORKED

     var style = document.createElement("style");
      style.innerHTML = `#divContainer{
        position: fixed;
      } #openButton{
        position: fixed;
      }`
      document.head.appendChild(style);

I am wondering why first did not worked anyone faced something similar?