I know this has been asked and answered many times but I've tried everything and nothing worked.
I have a HTML file as follows:
<div class="wrapper">
<div class="game-container">
<div class="canvas-container">
<canvas id="game-canvas" width="1024" height="640"></canvas>
<div id="control-area">
<span id="available-controls" ondrop="drop(event)" ondragover="allowDrop(event)">
<img src="resources/graphics/right.png" draggable="true" ondragstart="drag(event)" id="drag1">
</span>
</div>
<div id="action-area">
<span class="action" ondrop="drop(event)" ondragover="allowDrop(event)"></span>
</div>
</div>
</div>
</div>
My CSS looks like this:
.wrapper {
display: table;
padding: 0;
width: 100%;
height: 100%;
position: absolute;
}
.canvas-container {
position: relative;
max-width: 1024px;
margin: 0 auto;
}
#game-canvas {
width: 100%;
height: auto;
z-index: 0;
}
.game-container {
display: table-cell;
vertical-align: middle;
}
#available-controls {
width:64px;
height:64px;
border:1px solid #aaaaaa;
display: inline-block;
overflow: hidden;
}
#control-area{
display: block;
overflow: hidden;
}
#action-area{
display: block;
overflow: hidden;
}
.action {
width:64px;
height:64px;
border:1px solid #aaaaaa;
display: inline-block;
overflow: hidden;
}
CSS applies great to any element I write statically in the HTML, however, it NEVER applies to new elements I apply dynamically using JS. I add elements as follows:
function addAction() {
var newAction = document.createElement("span");
newAction.setAttribute('class', "action") || newAction.setAttribute('className', "action");
newAction.addEventListener("drop", drop);
newAction.addEventListener("dragover", allowDrop);
document.getElementById('action-area').appendChild(newAction);
}
I tried this in IE11, Firefox and Chrome and none of them applied CSS. Maybe worth mentioning I am using jQuery and Bootstrap 3. I have spent almost 3 days experimenting different things and nothing worked. I'd prefer not to use any library if possible.
EDIT: I'm adding a link to see whats happening, feel free to modify it.