My issue is the dynamically added div elements are not displaying horizontally within a container div element with a specific width. They always break into a new line.
Below is the code snippet I am using:
var i=1;
$(document).ready(function () {
$("#add").click(function(){
$('#container').append(
$('<div/>')
.addClass("dDiv")
.text("(hello world "+i+")")
);
i++;
});
})
#main{
float:right;
width:500px;
border: 1px solid;
overflow:hidden;
white-space: nowrap;
display: block;
}
.dDiv{
display: inline-block;
float:right;
background-color:#ff0000;
margin:2px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<div id="add">Add</div>
<div id="chat" style="float:right">
<div id="main">
<div id="container" style="float:right;">
</div>
</div>
</div>