Greetings! Currently, I am in the process of generating a dynamic form within a new tab using JavaScript. For some reason, the margin effects on the div element are not being applied correctly. Despite my attempts to set the margins using both classes and IDs in CSS as well as through div.setAttribute, they do not seem to take effect as expected. Here is the snippet of code that I am working with:
var openWindow = window.open('dynForm.html','_blank','');
var windoc=openWindow.document;
windoc.write("This is dynamic form ");
var div=document.createElement("div");
div.setAttribute("style","border:solid; margin-left:1cm; margin-right:1cm; margin-bottom:1cm; margin-top:1cm; background-color:lightblue;");
Right now, only the background color appears to be applying correctly in the new tab. Regardless of the specified margin values, the layout looks consistent. You can view how it appears by following this link to the screenshot provided: https://i.sstatic.net/laIdN.png
Question 2: Interestingly, even though I have defined classes and IDs in my CSS file, they do not seem to be properly applied to the div element.
#myDIV2{
background-color:lightblue;
}
I attempted setting an ID using div.id="myDIV2";
Additionally, I also tried div.setAttribute("id","myDIV2")
, but unfortunately, the outcome remains the same. The classes applied did not yield any noticeable changes in the display. I'm not quite sure what could be causing this issue or where I may have gone wrong. Any assistance would be greatly appreciated.